List of usage examples for javax.swing JTable getSelectedRow
@BeanProperty(bound = false) public int getSelectedRow()
From source file:ExtendedDnDDemo.java
protected void importString(JComponent c, String str) { JTable target = (JTable) c; DefaultTableModel model = (DefaultTableModel) target.getModel(); int index = target.getSelectedRow(); //Prevent the user from dropping data back on itself. //For example, if the user is moving rows #4,#5,#6 and #7 and //attempts to insert the rows after row #5, this would //be problematic when removing the original rows. //So this is not allowed. if (rows != null && index >= rows[0] - 1 && index <= rows[rows.length - 1]) { rows = null;/* w w w .ja v a 2 s . c o m*/ return; } int max = model.getRowCount(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; int colCount = target.getColumnCount(); for (int i = 0; i < values.length && i < colCount; i++) { model.insertRow(index++, values[i].split(",")); } }
From source file:labr_client.GUI.forms.EhealthSearch.java
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked // TODO add your handling code here: if (evt.getClickCount() == 2) { JTable target = (JTable) evt.getSource(); String id = (String) target.getValueAt(target.getSelectedRow(), 2); // setInfo(); }/*from w w w . j a v a2s. com*/ }
From source file:com.emr.schemas.SavedProcessesDataMover.java
/** * Constructor//w w w . j av a2 s .c o m */ public SavedProcessesDataMover() { initComponents(); this.setClosable(true); final Action processDelete = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String foreignKeysTable = (String) tblProcesses.getModel().getValueAt(modelRow, 0); if (foreignKeysTable == null || "".equals(foreignKeysTable)) { JOptionPane.showMessageDialog(null, "Table is Empty", "Empty Table", JOptionPane.ERROR_MESSAGE); } else { } } }; final SQLiteGetProcesses sp = new SQLiteGetProcesses(); sp.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { switch (event.getPropertyName()) { case "progress": System.out.println("Fetching data from db"); break; case "state": switch ((SwingWorker.StateValue) event.getNewValue()) { case DONE: try { model = sp.get(); tblProcesses.setModel(model); tblProcesses.getColumnModel().getColumn(0).setMaxWidth(300); //hide irrelevant columns tblProcesses.getColumnModel().getColumn(2).setMinWidth(0); tblProcesses.getColumnModel().getColumn(2).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(3).setMinWidth(0); tblProcesses.getColumnModel().getColumn(3).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(4).setMinWidth(0); tblProcesses.getColumnModel().getColumn(4).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(5).setMinWidth(0); tblProcesses.getColumnModel().getColumn(5).setMaxWidth(0); tblProcesses.getColumnModel().getColumn(6).setMinWidth(0); tblProcesses.getColumnModel().getColumn(6).setMaxWidth(0); ButtonColumn buttonColumn = new ButtonColumn(tblProcesses, processDelete, 7, "Delete"); } catch (final CancellationException ex) { Logger.getLogger(SavedProcessesDataMover.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(SavedProcessesDataMover.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(SavedProcessesDataMover.class.getName()).log(Level.SEVERE, null, ex); } break; } break; } } }); sp.execute(); tblProcesses.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { JTable target = (JTable) e.getSource(); int rowIndex = target.getSelectedRow(); String selectQry = (String) target.getModel().getValueAt(rowIndex, 2); String destinationTable = (String) target.getModel().getValueAt(rowIndex, 3); String truncateFirst = (String) target.getModel().getValueAt(rowIndex, 4); String destinationColumns = (String) target.getModel().getValueAt(rowIndex, 5); String columnsToBeMapped = (String) target.getModel().getValueAt(rowIndex, 6); lblUpdateText.setText("<html><b color='red'>Moving Data</b></html>"); dbProgressBar.setIndeterminate(true); new DBUpdater(selectQry, destinationTable, truncateFirst, destinationColumns, columnsToBeMapped) .execute(); } } @Override public void mousePressed(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseReleased(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseEntered(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseExited(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); }
From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java
private void deleteCoreDataObject(final EventList<?> objectsList, final JTable table) { if (!objectsList.isEmpty()) { int selectedClientIndex = table.getSelectedRow(); checkState(selectedClientIndex >= 0, "Cannot delete item. No row selected in table."); log.debug("Deleting item: {}", objectsList.get(selectedClientIndex)); objectsList.remove(selectedClientIndex); activeCoreDataObject = null;/* w w w . j av a 2s . c om*/ if (selectedClientIndex >= 0) { int newIndex = max(0, selectedClientIndex - 1); table.getSelectionModel().setSelectionInterval(newIndex, newIndex); } } }
From source file:au.org.ala.delta.editor.ui.ActionSetsDialog.java
private DirectiveFile getSelectedFile() { JTable selectedTable = (JTable) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport().getView(); int selected = selectedTable.getSelectedRow(); DirectiveFile file = null;// ww w . j a v a2s. c om if (selected >= 0) { // Convert view index to model index (we have a row sorter active). selected = selectedTable.convertRowIndexToModel(selected); file = ((DirectiveFileTableModel) selectedTable.getModel()).getFileAt(selected); } return file; }
From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java
private <T extends AbstractNamedObject<T>> void addCoreDataObject(final EventList<T> objectsList, final T object, final JTable table) { checkAndResetActiveCoreDataObject(); log.debug("Adding a new item..."); objectsList.add(object);//from www . j av a2 s. co m activeCoreDataObject = object; int index = objectsList.size() - 1; if (index == -1) { index = table.getSelectedRow(); } table.changeSelection(index, 0, false, false); }
From source file:fll.subjective.SubjectiveFrame.java
/** * Show differences./* w w w .j av a 2s. c o m*/ */ private void showDifferencesDialog(final Collection<SubjectiveScoreDifference> diffs) { final SubjectiveDiffTableModel model = new SubjectiveDiffTableModel(diffs); final JTable table = new JTable(model); table.setGridColor(Color.BLACK); table.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (e.getClickCount() == 2) { final JTable target = (JTable) e.getSource(); final int row = target.getSelectedRow(); final SubjectiveScoreDifference diff = model.getDiffForRow(row); // find correct table final String category = diff.getCategory(); final JTable scoreTable = getTableForTitle(category); final int tabIndex = getTabIndexForCategory(category); getTabbedPane().setSelectedIndex(tabIndex); // get correct row and column final SubjectiveTableModel model = (SubjectiveTableModel) scoreTable.getModel(); final int scoreRow = model.getRowForTeamAndJudge(diff.getTeamNumber(), diff.getJudge()); final int scoreCol = model.getColForSubcategory(diff.getSubcategory()); if (scoreRow == -1 || scoreCol == -1) { throw new FLLRuntimeException( "Internal error: Cannot find correct row and column for score difference: " + diff); } scoreTable.changeSelection(scoreRow, scoreCol, false, false); } } }); final JDialog dialog = new JDialog(this, false); final Container cpane = dialog.getContentPane(); cpane.setLayout(new BorderLayout()); final JScrollPane tableScroller = new JScrollPane(table); cpane.add(tableScroller, BorderLayout.CENTER); dialog.pack(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); }
From source file:me.mayo.telnetkek.MainPanel.java
public final PlayerInfo getSelectedPlayer() { final JTable table = MainPanel.this.tblPlayers; final int selectedRow = table.getSelectedRow(); if (selectedRow < 0 || selectedRow >= playerList.size()) { return null; }//ww w. java 2 s. c o m return playerList.get(table.convertRowIndexToModel(selectedRow)); }
From source file:bio.gcat.gui.BDATool.java
private void enableBinaryDichotomicAlgorithmMenus() { JTable table = bdaPanel.table; javax.swing.table.TableModel bdas = table.getModel(); int size = bdas.getRowCount(), index = table.getSelectedRow(); boolean filled = size != 0, selected = filled && index != -1; getMenuItem(menubar, ACTION_BDA_EDIT).setEnabled(selected && index < size); //BinaryDichotomicAlgorithm bda = bdas.get(index); !isPredefined(bda); getMenuItem(menubar, ACTION_BDA_MOVE_UP).setEnabled(index > 0); getMenuItem(menubar, ACTION_BDA_MOVE_DOWN).setEnabled(selected && index < size - 1); getMenuItem(menubar, ACTION_BDA_REMOVE).setEnabled(selected); getMenuItem(menubar, ACTION_BDAS_CLEAR).setEnabled(filled); }
From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java
BamFrame(List<BamFileRef> BamFileRefs) { super((JFrame) null, "Bam View (" + BamFileRefs.size() + " files)", ModalityType.APPLICATION_MODAL); this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); this.BamFileRefs = BamFileRefs; addWindowListener(new WindowAdapter() { @Override/* ww w .ja va2s .c o m*/ public void windowOpened(WindowEvent e) { removeWindowListener(this); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); d.width -= 150; d.height -= 150; for (BamFileRef vfr : BamFrame.this.BamFileRefs) { LOG.info("Reading " + vfr.bamFile); int w = (int) (d.width * 0.8); int h = (int) (d.height * 0.8); BamInternalFrame iFrame = new BamInternalFrame(vfr); iFrame.setBounds(Math.max((int) ((d.width - w) * Math.random()), 0), Math.max((int) ((d.height - h) * Math.random()), 0), w, h); desktopPane.add(iFrame); BamInternalFrames.add(iFrame); iFrame.setVisible(true); iFrame.jTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { JTable t = (JTable) e.getSource(); int row = t.getSelectedRow(); if (row == -1) return; BamTableModel tm = (BamTableModel) t.getModel(); showIgv(tm.getValueAt(row, 0), tm.getValueAt(row, 1)); } } }); } reloadFrameContent(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { doMenuClose(); } }); JMenuBar bar = new JMenuBar(); setJMenuBar(bar); JMenu menu = new JMenu("File"); bar.add(menu); menu.add(new AbstractAction("Quit") { @Override public void actionPerformed(ActionEvent e) { doMenuClose(); } }); menu = new JMenu("Flags"); bar.add(menu); for (SamFlag flag : SamFlag.values()) { JCheckBox cbox = new JCheckBox("Require " + flag); requiredFlags.add(cbox); menu.add(cbox); } menu.add(new JSeparator()); for (SamFlag flag : SamFlag.values()) { JCheckBox cbox = new JCheckBox("Filter out " + flag); filteringFlags.add(cbox); menu.add(cbox); } JPanel contentPane = new JPanel(new BorderLayout(5, 5)); setContentPane(contentPane); this.desktopPane = new JDesktopPane(); contentPane.add(this.desktopPane, BorderLayout.CENTER); JPanel top = new JPanel(new FlowLayout(FlowLayout.LEADING)); contentPane.add(top, BorderLayout.NORTH); JLabel lbl = new JLabel("Max Rows:", JLabel.LEADING); JSpinner spinner = new JSpinner(this.numFetchModel = new SpinnerNumberModel(100, 1, 10000, 10)); lbl.setLabelFor(spinner); top.add(lbl); top.add(spinner); lbl = new JLabel("Timeout (secs):", JLabel.LEADING); spinner = new JSpinner(this.numSecondsModel = new SpinnerNumberModel(2, 1, 10000, 1)); lbl.setLabelFor(spinner); top.add(lbl); top.add(spinner); //lbl=new JLabel("JEXL:",JLabel.LEADING); /*jexlField=new JTextField(20); lbl.setLabelFor(jexlField); top.add(lbl); top.add(jexlField);*/ lbl = new JLabel("Region:", JLabel.LEADING); selectRgnField = new JTextField(20); lbl.setLabelFor(selectRgnField); AbstractAction action = new AbstractAction("Select") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent a) { if ( /* (jexlField.getText().trim().isEmpty() || parseJex(jexlField.getText().trim())!=null) && */ (selectRgnField.getText().trim().isEmpty() || parseOne(selectRgnField.getText()) != null)) { reloadFrameContent(); } else { LOG.info("Bad input " + selectRgnField.getText()); } } }; selectRgnField.addActionListener(action); //jexlField.addActionListener(action); top.add(lbl); top.add(selectRgnField); top.add(new JButton(action)); }