List of usage examples for javax.swing JTable isRowSelected
public boolean isRowSelected(int row)
From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzResultDialog.java
@Override public JXTreeTable getTable() { if (table == null) { if (model == null) { model = new HttpFuzzTableModel(); }/*from w ww. j a v a 2s . c om*/ table = new JXTreeTable(model); table.setDoubleBuffered(true); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setName("HttpFuzzResultTable"); table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12)); table.setDefaultRenderer(Pair.class, new IconTableCellRenderer()); int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 }; for (int i = 0, count = widths.length; i < count; i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } @Override public void mouseReleased(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) { if (e.isPopupTrigger()) { if (e.isPopupTrigger()) { // Select list item on right click JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.changeSelection(row, 0, false, false); } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } } }); table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() { @Override public void valueChanged(javax.swing.event.ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (table.getSelectedRowCount() == 0) { return; } final int row = table.getSelectedRow(); if (getEntry(row) instanceof HttpFuzzRequestRecord) { final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row)) .getHistory(); try { getMessageInspection().setMessage(historyReference.getHttpMessage()); } catch (HttpMalformedHeaderException | SQLException ex) { logger.error(ex.getMessage(), ex); } } updateValues(); redrawDiagrams(); } } }); } table.getTableHeader().addMouseListener(new MouseListener() { int sortedOn = -1; @Override public void mouseReleased(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent e) { int index = table.columnAtPoint(e.getPoint()); List<HttpFuzzRecord> list = model.getEntries(); if (list.size() == 0) { return; } HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator(); comp.setFeature(index); if (index == sortedOn) { Collections.sort(list, comp); Collections.reverse(list); sortedOn = -1; } else { Collections.sort(list, comp); sortedOn = index; } table.updateUI(); } }); table.setRootVisible(false); table.setVisible(true); return table; }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java
private void setControlDefaults() { String[] colName = { "Delays (ps)" }; int max = 16666; try {//from w ww. j ava 2 s .c o m max = Integer.parseInt(core_.getProperty("Laser", "Frequency")); } catch (Exception e) { } tableModel_ = new DelayTableModel(colName, (sap_.getDelaysArray()).get(0), 0, max, 25); tableModel_.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { sap_.setDelaysArray(0, tableModel_.getData()); fm_.setGatingData((sap_.getDelaysArray()).get(0)); var_.delays = tableModel_.getData(); } }); delayTable_ = new JTable() { @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component comp = super.prepareRenderer(renderer, row, column); int modelRow = convertRowIndexToModel(row); int modelColumn = convertColumnIndexToModel(column); if (modelColumn != 0 && modelRow != 0) { comp.setBackground(Color.GREEN); } return comp; } }; delayTable_.setModel(tableModel_); delayTable_.setSurrendersFocusOnKeystroke(true); delayTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); JScrollPane scroller = new javax.swing.JScrollPane(delayTable_); delayTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(60, 100)); delayTablePanel.setLayout(new BorderLayout()); delayTablePanel.add(scroller, BorderLayout.CENTER); final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete delay"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = delayTable_.getSelectedRow(); tableModel_.removeRow(r); } }); JMenuItem addItem = new JMenuItem("Add delay"); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = delayTable_.getSelectedRow(); tableModel_.insertRow(r + 1, 0); } }); popupMenu.add(addItem); popupMenu.add(deleteItem); delayTable_.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { // System.out.println("pressed"); } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable) e.getSource(); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); if (!source.isRowSelected(row)) source.changeSelection(row, column, false, false); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); // Set up slider controls mcpSlider_ = new SliderControl("MCP voltage (V)", 300, 850, 750); mcpVoltagePanel.setLayout(new BorderLayout()); mcpVoltagePanel.add(mcpSlider_, BorderLayout.SOUTH); mcpSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { mcpSliderPropertyChange(evt); } }); gatewidthSlider_ = new SliderControl("Gate width (ps)", 200, 7000, 3000); gatewidthPanel.setLayout(new BorderLayout()); gatewidthPanel.add(gatewidthSlider_, BorderLayout.SOUTH); gatewidthSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { gatewidthSliderPropertyChange(evt); } }); HRIControlsPanel.revalidate(); HRIControlsPanel.repaint(); slowDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0); slowCurrentDelayPanel.setLayout(new BorderLayout()); slowCurrentDelayPanel.add(slowDelaySlider_, BorderLayout.SOUTH); slowDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { slowDelaySlider_.setValue(tableModel_.validateData(slowDelaySlider_.getValue().intValue())); slowDelaySliderPropertyChange(evt); } }); fastDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0); fastCurrentDelayPanel.setLayout(new BorderLayout()); fastCurrentDelayPanel.add(fastDelaySlider_, BorderLayout.SOUTH); fastDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { fastDelaySlider_.setValue(tableModel_.validateData(fastDelaySlider_.getValue().intValue())); fastDelaySliderPropertyChange(evt); } }); delayBoxTabbedPane.revalidate(); delayBoxTabbedPane.repaint(); fm_ = new FindMaxpoint(); maxpointGraphPanel.setLayout(new BorderLayout()); chartPanel_ = new ChartPanel(fm_.getChart()); maxpointGraphPanel.add(chartPanel_, BorderLayout.NORTH); // for some reason maxpointGraphPanel's height and width are returned 0 // so hardcode for now... chartPanel_.setMaximumDrawWidth(500); chartPanel_.setMaximumDrawHeight(200); chartPanel_.setPreferredSize(new Dimension(500, 200)); // Set values for other controls based on underlying data to ensure // that all controls are in a consistent state. scanDelCheck.setSelected(sap_.getUseScanFLIM()); }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.GUIComponents.XYSequencing.java
private void setControlDefaults() { pmdp_ = new PlateMapDrawPanel(this); sap_ = SeqAcqProps.getInstance();// ww w . j a v a2 s.c o m plateMapBasePanel.setLayout(new BorderLayout()); plateMapBasePanel.add(pmdp_, BorderLayout.CENTER); tableModel_ = new FOVTableModel(pp_); searchFOVtableModel_ = new FOVTableModel(pp_); //Not sure if this is the best way, but try it for now. tableModel_.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { } }); fovTable_ = new JTable(); fovTable_.setModel(tableModel_); fovTable_.setSurrendersFocusOnKeystroke(true); fovTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); JScrollPane scroller = new javax.swing.JScrollPane(fovTable_); fovTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(190, 130)); fovTablePanel.setLayout(new BorderLayout()); fovTablePanel.add(scroller, BorderLayout.CENTER); final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete FOV"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fovTable_.getSelectedRow(); tableModel_.removeRow(r); } }); JMenuItem addItem = new JMenuItem("Add FOV"); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fovTable_.getSelectedRow(); tableModel_.insertRow(r, new FOV("A1", pp_, 6000)); } }); JMenuItem goToFOVItem = new JMenuItem("Go to FOV"); goToFOVItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fovTable_.getSelectedRow(); // FOV fov = tableModel_.getData().get(r); xyzmi_.gotoFOV(tableModel_.getData().get(r)); if (!zAsOffset_) { double zval = tableModel_.getData().get(r).getZ(); xyzmi_.moveZAbsolute(zval); } else { // obviously, this isn't quite right - we want to get // the offset of the CURRENT FOV (perhaps from parent in // later implementations?) and subtract from that of the // NEWLY SELECTED FOV. // TODO: fix for proper zAsOffset behaviour. // Wait for move completion while (xyzmi_.isStageBusy()) { System.out.println("Stage moving..."); } ; if (parent_.checkifAFenabled()) { // If we have gone to the FOV, and have AF, do AF xyzmi_.customAutofocus(parent_.getAFOffset()); } else { // If we don't have AF, go to the 'good offset position' xyzmi_.moveZAbsolute(parent_.getFixedAFDefault()); } //Now do the relative shift xyzmi_.moveZRelative(tableModel_.getData().get(r).getZ()); System.out.println("Z value" + tableModel_.getData().get(r).getZ()); } } }); popupMenu.add(addItem); popupMenu.add(deleteItem); popupMenu.add(goToFOVItem); fovTable_.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { // System.out.println("pressed"); } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable) e.getSource(); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); if (!source.isRowSelected(row)) { source.changeSelection(row, column, false, false); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); // fovTable_.setDefaultRenderer(FOV.class, new TableRenderer()); setupInsertComboBox(); }
From source file:dataviewer.DataViewer.java
private void renderData(DefaultTableModel model) { tb_data.setVisible(false);/*from w ww. j a v a 2s . c o m*/ tb_data.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(row % 2 == 0 ? Color.WHITE : new Color(240, 240, 240)); if (table.isCellSelected(row, column)) { c.setBackground(new Color(200, 0, 0)); c.setForeground(Color.white); } else if (table.isRowSelected(row)) { c.setBackground(new Color(0, 0, 200)); c.setForeground(Color.white); } else { c.setForeground(Color.black); } return c; } }); tb_data.setGridColor(new Color(220, 220, 220)); tb_data.setShowVerticalLines(true); tb_data.setModel(model); for (int i = 0; i < model.getColumnCount(); ++i) { if (model.getColumnName(i).equals("_N_")) { TableRowSorter trs = new TableRowSorter(model); trs.setComparator(i, new IntComparator()); tb_data.setRowSorter(trs); } } for (int j = 0; j < tb_data.getColumnCount(); j++) { int width = 0; TableColumn col = tb_data.getColumnModel().getColumn(j); TableCellRenderer renderer = tb_data.getTableHeader().getDefaultRenderer(); Component comp = renderer.getTableCellRendererComponent(tb_data, col.getHeaderValue(), false, false, 0, 0); width = Math.max(comp.getPreferredSize().width, width); for (int i = 0; i < tb_data.getRowCount(); i++) { renderer = tb_data.getCellRenderer(i, j); comp = tb_data.prepareRenderer(renderer, i, j); width = Math.max(comp.getPreferredSize().width, width); } tb_data.getColumnModel().getColumn(j).setPreferredWidth(width + 20); } tb_data.setVisible(true); }
From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java
private void sedsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sedsTableMousePressed if (evt.isPopupTrigger()) { JTable source = (JTable) evt.getSource(); int row = source.rowAtPoint(evt.getPoint()); int column = source.columnAtPoint(evt.getPoint()); if (!source.isRowSelected(row)) source.changeSelection(row, column, false, false); sedsTable.changeSelection(row, column, false, false); jPopupMenu2.show(evt.getComponent(), evt.getX(), evt.getY()); }/*from w w w . ja v a 2 s .co m*/ }
From source file:org.simmi.GeneSetHead.java
License:asdf
public Set<String> getSelspec(Component comp, final List<String> specs, final JCheckBox... contigs) { final JTable table = new JTable(); table.setDragEnabled(true);//from w ww . j av a2 s.c o m JScrollPane scroll = new JScrollPane(table); table.setAutoCreateRowSorter(true); final List<Sequence> ctgs = new ArrayList<Sequence>(geneset.contigmap.values()); final TableModel contigmodel = new TableModel() { @Override public int getRowCount() { return ctgs.size(); } @Override public int getColumnCount() { return 1; } @Override public String getColumnName(int columnIndex) { return "Contigs/Scaffolds"; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return ctgs.get(rowIndex).toString(); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; final TableModel specmodel = new TableModel() { @Override public int getRowCount() { return specs.size(); } @Override public int getColumnCount() { return 2; } @Override public String getColumnName(int columnIndex) { return columnIndex == 0 ? "Id" : "Spec"; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 1) return Sequence.nameFix(specs.get(rowIndex), true); else return specs.get(rowIndex); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; table.setModel(specmodel); TransferHandler th = dragRows(table, specs); table.setTransferHandler(th); if (contigs != null && contigs.length > 0 && !contigs[0].getText().equals("Plasmid")) contigs[0].addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (contigs[0] != null && contigs[0].isSelected()) table.setModel(contigmodel); else table.setModel(specmodel); } }); Object[] ctls = new Object[] { scroll, contigs }; //Object[] ctls2 = new Object[] { scroll }; //if( contigs != null ) JOptionPane.showMessageDialog(comp, ctls); //else JOptionPane.showMessageDialog( comp, ctls2 ); Set<String> selspec = new LinkedHashSet<>(); for (int i = 0; i < table.getRowCount(); i++) { if (table.isRowSelected(i)) { String spec = (String) table.getValueAt(i, 0); System.err.println("test " + spec); selspec.add(spec); } } return selspec; }
From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java
public JXTreeTable getFuzzResultTable() { if (fuzzResultTable == null) { resetFuzzResultTable();/* ww w .j ava2 s . c o m*/ fuzzResultTable = new JXTreeTable(getResultsModel()); fuzzResultTable.setName("HttpFuzzResultTable"); fuzzResultTable.setDoubleBuffered(true); fuzzResultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); fuzzResultTable.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12)); fuzzResultTable.setDefaultRenderer(Pair.class, new IconTableCellRenderer()); int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 }; for (int i = 0, count = widths.length; i < count; i++) { TableColumn column = fuzzResultTable.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } fuzzResultTable.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } @Override public void mouseReleased(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) { if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) { // Select list item on right click JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.changeSelection(row, 0, false, false); } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); fuzzResultTable.getSelectionModel() .addListSelectionListener(new javax.swing.event.ListSelectionListener() { @Override public void valueChanged(javax.swing.event.ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (fuzzResultTable.getSelectedRowCount() == 0) { return; } final int row = fuzzResultTable.getSelectedRow(); if (getEntry(row) instanceof HttpFuzzRequestRecord) { final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry( row)).getHistory(); try { displayMessage(historyReference.getHttpMessage()); } catch (HttpMalformedHeaderException | SQLException ex) { logger.error(ex.getMessage(), ex); } } } } }); fuzzResultTable.getTableHeader().addMouseListener(new MouseListener() { int sortedOn = -1; @Override public void mouseReleased(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent e) { int index = fuzzResultTable.columnAtPoint(e.getPoint()); List<HttpFuzzRecord> list = getResultsModel().getEntries(); if (list.size() == 0) { return; } HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator(); comp.setFeature(index); if (index == sortedOn) { Collections.sort(list, comp); Collections.reverse(list); sortedOn = -1; } else { Collections.sort(list, comp); sortedOn = index; } fuzzResultTable.updateUI(); } }); fuzzResultTable.setRootVisible(false); fuzzResultTable.setVisible(true); } return fuzzResultTable; }
From source file:pcgen.gui2.tabs.EquipInfoTab.java
private List<Integer> getMenuTargets(JTable table, MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.setRowSelectionInterval(row, row); }//from w w w .ja v a2s. c om List<Integer> targets = new ArrayList<>(); for (int selRow : table.getSelectedRows()) { targets.add(selRow); } return targets; }