List of usage examples for javax.swing JTable rowAtPoint
public int rowAtPoint(Point point)
point
lies in, or -1 if the result is not in the range [0, getRowCount()
-1]. From source file:io.heming.accountbook.ui.MainFrame.java
private void initTablePopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteMenuItem = new JMenuItem("(D)", new ImageIcon(getClass().getResource("edit-delete-6.png"))); deleteMenuItem.setMnemonic('D'); popupMenu.add(deleteMenuItem);/*from w w w .j a v a 2 s . c om*/ deleteMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteRecord(); } }); popupMenu.addSeparator(); JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png"))); editMenuItem.setMnemonic('E'); popupMenu.add(editMenuItem); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow())); showUpdateRecordDialog(record); } }); // ??popup menu table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (disable) return; JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(e.getPoint()); if (SwingUtilities.isRightMouseButton(e)) { if (row >= 0 && col >= 0) { table.setRowSelectionInterval(row, row); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } else if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 2) { if (row >= 0 && col >= 0) { // Record record = model.getRecord(table.convertRowIndexToModel(row)); // showUpdateRecordDialog(record); } } } } }); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table.getActionMap().put("Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { if (disable) return; //do something on JTable enter pressed int row = table.getSelectedRow(); if (row >= 0) { Record record = model.getRecord(table.convertRowIndexToModel(row)); showUpdateRecordDialog(record); } } }); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java
private SampleGroupViewer(String title, KdxploreDatabase kdxdb, Trial trial, SampleGroup sampleGroup) { super(new BorderLayout()); this.title = title; // setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.kdxdb = kdxdb; this.trial = trial; this.sampleGroup = sampleGroup; initialise();/*from www .j av a 2 s .co m*/ if (plotInfoByPlotId.isEmpty()) { add(new JLabel("No Plots available"), BorderLayout.CENTER); } else { tiChoiceTableModel = new TraitInstanceChoiceTableModel(); JTable tiTable = new JTable(tiChoiceTableModel); tiTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { List<Integer> modelRows = GuiUtil.getSelectedModelRows(tiTable); if (modelRows.isEmpty()) { Point pt = e.getPoint(); int vrow = tiTable.rowAtPoint(pt); if (vrow >= 0) { int mrow = tiTable.convertRowIndexToModel(vrow); if (mrow >= 0) { showPopupMenu(tiTable, pt, Arrays.asList(Integer.valueOf(mrow))); } } } else { showPopupMenu(tiTable, e.getPoint(), modelRows); } } } }); tableModel = new DataTableModel(plotInfoByPlotId); JTable table = new JTable(tableModel); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(String.class, r); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tiTable), new JScrollPane(table)); splitPane.setResizeWeight(0.2); add(splitPane, BorderLayout.CENTER); table.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(table, true)); } }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.GUIComponents.XYSequencing.java
private void setControlDefaults() { pmdp_ = new PlateMapDrawPanel(this); sap_ = SeqAcqProps.getInstance();//from w ww .jav a 2s .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: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.j a va 2s . c om*/ }
From source file:com.u2apple.tool.ui.MainFrame.java
private void initRowSelectionEvent() { deviceTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { int row = deviceTable.getSelectedRow(); //When refresh table model data, row will be -1. if (row >= 0) { String vid = (String) deviceTable.getValueAt(row, 0); String model = (String) deviceTable.getValueAt(row, 1); String brand = (String) deviceTable.getValueAt(row, 2); vidTextField.setText(vid);//from ww w. j ava 2 s . co m modelTextField.setText(model); brandTextField.setText(brand); } //Auto fullfil device information. initDevice(); }); deviceTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = table.rowAtPoint(p); if (me.getClickCount() == 2) { String vid = (String) deviceTable.getValueAt(row, 0); String model = (String) deviceTable.getValueAt(row, 1); String brand = (String) deviceTable.getValueAt(row, 2); AndroidDeviceRanking androidDevice = new AndroidDeviceRanking(); androidDevice.setVid(vid); androidDevice.setRoProductModel(model); androidDevice.setRoProductBrand(brand); androidDevice.setCheckDate(new Date()); try { DeviceCache.markDeviceChecked(androidDevice); } catch (JAXBException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } DeviceTableModel tableModel = (DeviceTableModel) deviceTable.getModel(); tableModel.removeRow(row); } } }); }
From source file:com.intuit.tank.proxy.ProxyApp.java
private JPanel getTransactionTable() { JPanel frame = new JPanel(new BorderLayout()); model = new TransactionTableModel(); final JTable table = new TransactionTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/* ww w. j ava 2 s .c o m*/ final JPopupMenu pm = new JPopupMenu(); JMenuItem item = new JMenuItem("Delete Selected"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { int response = JOptionPane.showConfirmDialog(ProxyApp.this, "Are you sure you want to delete " + selectedRows.length + " Transactions?", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { int[] correctedRows = new int[selectedRows.length]; for (int i = selectedRows.length; --i >= 0;) { int row = selectedRows[i]; int index = (Integer) table.getValueAt(row, 0) - 1; correctedRows[i] = index; } Arrays.sort(correctedRows); for (int i = correctedRows.length; --i >= 0;) { int row = correctedRows[i]; Transaction transaction = model.getTransactionForIndex(row); if (transaction != null) { model.removeTransaction(transaction, row); isDirty = true; saveAction.setEnabled(isDirty && !stopAction.isEnabled()); } } } } } }); pm.add(item); table.add(pm); table.addMouseListener(new MouseAdapter() { boolean pressed = false; public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int index = (Integer) table.getValueAt(row, 0) - 1; Transaction transaction = model.getTransactionForIndex(index); if (transaction != null) { detailsTF.setText(transaction.toString()); detailsTF.setCaretPosition(0); detailsDialog.setVisible(true); } } } /** * @{inheritDoc */ @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { pressed = true; int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } /** * @{inheritDoc */ @Override public void mouseReleased(MouseEvent e) { if (!pressed && e.isPopupTrigger()) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } }); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter: "); panel.add(label, BorderLayout.WEST); final JLabel countLabel = new JLabel(" Count: 0 "); panel.add(countLabel, BorderLayout.EAST); final JTextField filterText = new JTextField(""); filterText.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { try { sorter.setRowFilter(RowFilter.regexFilter(text)); countLabel.setText(" Count: " + sorter.getViewRowCount() + " "); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } } }); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); return frame; }
From source file:com.osparking.attendant.AttListForm.java
private boolean rowHidden(JTable usersTable, int i) { Rectangle vr = usersTable.getVisibleRect(); int first = usersTable.rowAtPoint(vr.getLocation()); vr.translate(0, vr.height);/*from ww w . ja v a 2 s . co m*/ int visibleRows = usersTable.rowAtPoint(vr.getLocation()) - first; if (i < visibleRows) { return false; } else { return true; } }
From source file:com.peterbochs.PeterBochsDebugger.java
public void instructionTableMouseClicked(MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) { JTable jTable = (JTable) evt.getSource(); if (jTable == instructionTable) { Global.clickedWhichInstructionPanel = 0; } else {/* w ww.j a v a 2 s .c o m*/ Global.clickedWhichInstructionPanel = 1; } // select Point p = evt.getPoint(); int rowNumber = jTable.rowAtPoint(p); int columnNumber = jTable.columnAtPoint(p); ListSelectionModel model = jTable.getSelectionModel(); model.setSelectionInterval(rowNumber, rowNumber); jTable.getColumnModel().getSelectionModel().setSelectionInterval(columnNumber, columnNumber); // end select getJInstructionPanelPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createDeelnemersPanel() { JPanel panel = new JPanel(false); panel.setBackground(Color.BLACK); //panel.setLayout(new GridLayout(1, 0)); panel.setLayout(new BorderLayout()); JPanel innerPanel = new JPanel(); JLabel lbAanwezig = new JLabel("Deelnemers: "); innerPanel.add(lbAanwezig, BorderLayout.NORTH); tfAanwezig = new JLabel(Integer.toString(status.deelnemers.aantalAanwezig()), 10); innerPanel.add(tfAanwezig, BorderLayout.NORTH); //innerPanel.setLayout(new GridLayout(1, 0)); innerPanel.add(new JLabel("Naam:"), BorderLayout.NORTH); JTextField deelnemer = new JTextField(15); ArrayList<String> words = new ArrayList<>(); if (status.OSBOSpelers != null) { for (Speler s : status.OSBOSpelers.values()) { words.add(s.getNaam().trim()); words.add(Integer.toString(s.getKnsbnummer())); }//from w ww. j a v a 2 s .com } @SuppressWarnings("unused") Suggesties suggesties = new Suggesties(deelnemer, this, words, 2); innerPanel.add(deelnemer, BorderLayout.NORTH); deelnemer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); JButton btVoegToe = new JButton("Voeg toe"); btVoegToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); innerPanel.add(btVoegToe); panel.add(innerPanel); // panel_deelnemers.add(new JLabel("Deelnemers IJSCO toernooi")); deelnemersModel = new DeelnemersModel(panel, status.deelnemers); JTable deelnemersTabel = new JTable(deelnemersModel) { private static final long serialVersionUID = -8293073016982337108L; @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); DeelnemersModel model = (DeelnemersModel) getModel(); // Tooltip if (c instanceof JComponent) { ((JComponent) c) .setToolTipText(model.getToolTip(convertRowIndexToModel(row), column).toString()); } // Alternate row color if (!isRowSelected(row)) { c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY); } // Highlight overruled entries if (status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam() || status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam()) { c.setForeground(Color.BLUE); } else { c.setForeground(Color.BLACK); } return c; } }; deelnemersTabel.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { status.groepen = null; status.schemas = null; status.schema = null; groepenText.setText(""); schemaModel.setSchemas(null); schemaModel.fireTableDataChanged(); if (status.deelnemers != null && tfAanwezig != null) { tfAanwezig.setText(Integer.toString(status.deelnemers.aantalAanwezig())); } panel.repaint(); } }); deelnemersTabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { logger.log(Level.INFO, "MouseEvent on table fired, type : " + e.toString()); logger.log(Level.INFO, "Popup trigger? : " + e.isPopupTrigger()); if (e.isPopupTrigger()) { int row = deelnemersTabel.rowAtPoint(e.getPoint()); JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Bewerk speler"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Bewerk Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); BewerkSpelerDialoog rd = new BewerkSpelerDialoog(new JFrame(), "Bewerk Speler", s, deelnemersModel); rd.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { System.out.println("closing..."); } }); rd.setVisible(true); } }); popup.add(menuItem); menuItem = new JMenuItem("Verwijder Speler"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Verwijder Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); status.deelnemers.remove(s); deelnemersModel.fireTableDataChanged(); } }); popup.show(e.getComponent(), e.getX(), e.getY()); } } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(deelnemersTabel); innerPanel.add(scrollPane, BorderLayout.CENTER); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(deelnemersModel); deelnemersTabel.setRowSorter(sorter); innerPanel.add(new JLabel("Filter op : ")); JTextField tfFilter = new JTextField(10); tfFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(tfFilter); JButton btPasToe = new JButton("Apply"); btPasToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(btPasToe); JButton btWis = new JButton("Wis"); btWis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { tfFilter.setText(""); logger.log(Level.INFO, "Wis filter"); sorter.setRowFilter(null); } }); innerPanel.add(btWis); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(0), 30); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(1), 55); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(2), 170); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(3), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(4), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(5), 30); Utils.fixedComponentSize(scrollPane, 400, 580); return panel; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java
private void jobQueueMousePressedCommon(java.awt.event.MouseEvent evt, JTable table) { if (evt.isPopupTrigger()) { if (table.getSelectedRowCount() == 0) { int row = table.rowAtPoint(evt.getPoint()); if (row > -1) { table.setRowSelectionInterval(row, row); }/*from w ww . j a v a 2s . com*/ } JPopupMenu menu = depositPresenter.getJobQueueMenu((JTable) evt.getSource()); if (menu != null) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }