Java Code Examples for javax.swing.JTable#rowAtPoint()
The following examples show how to use
javax.swing.JTable#rowAtPoint() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RTable.java From marathonv5 with Apache License 2.0 | 6 votes |
public RTable(Component source, JSONOMapConfig omapConfig, Point point, IJSONRecorder recorder) { super(source, omapConfig, point, recorder); JTable table = (JTable) source; if (table.isEditing()) { column = table.getEditingColumn(); row = table.getEditingRow(); } else { if (point != null) { row = table.rowAtPoint(point); column = table.columnAtPoint(point); } else { row = table.getSelectedRow(); column = table.getSelectedColumn(); } } if (row == -1 || column == -1) { row = column = -1; } }
Example 2
Source File: ComboBoxTableCellEditor.java From netbeans with Apache License 2.0 | 6 votes |
/********************************************************************** * Is the cell editable? If the mouse was pressed at a margin * we don't want the cell to be editable. * * @param evt The event-object. * * @interfaceMethod javax.swing.table.TableCellEditor *********************************************************************/ public boolean isCellEditable (EventObject evt) { this.startEditingEvent = evt; if (evt instanceof MouseEvent && evt.getSource () instanceof JTable) { MouseEvent me = (MouseEvent) evt; JTable table = (JTable) me.getSource (); Point pt = new Point (me.getX (), me.getY ()); int row = table.rowAtPoint (pt); int col = table.columnAtPoint (pt); Rectangle rec = table.getCellRect (row, col, false); if (me.getY () >= rec.y + rec.height || me.getX () >= rec.x + rec.width) { return false; } } return super.isCellEditable (evt); }
Example 3
Source File: DeckCellRenderer.java From magarena with GNU General Public License v3.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String deckName = (String) value; JLabel lbl = new JLabel(deckName); lbl.setOpaque(true); if (isSelected) { lbl.setForeground(table.getSelectionForeground()); lbl.setBackground(table.getSelectionBackground()); } else { lbl.setForeground(table.getForeground()); lbl.setBackground(table.getBackground()); } Point mp = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(mp, table); int mRow = table.rowAtPoint(mp); int mCol = table.columnAtPoint(mp); if (row == mRow && column == mCol) { lbl.setForeground(Color.blue); lbl.setFont(withUnderline); } return lbl; }
Example 4
Source File: TableRendererTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean isCellEditable(EventObject anEvent) { if (anEvent.getSource() instanceof JTable) { JTable table = (JTable) anEvent.getSource(); if (anEvent instanceof MouseEvent) { MouseEvent event = (MouseEvent) anEvent; Point p = event.getPoint(); int row = table.rowAtPoint(p); int col = table.columnAtPoint(p); Rectangle rect = table.getCellRect(row, col, true); p.translate(-rect.x, -rect.y); System.out.println("isCellEditable("+anEvent+")"); System.out.println("Point "+p+"in rectangle "+rect); if (p.x > rect.width - 24) { // last 24 points not editable return false; } } } return true; }
Example 5
Source File: PurchaseInfoTab.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private static List<EquipmentFacade> getMenuTargets(JTable table, MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { if ((row >= 0) && (table.getRowCount() > row)) { table.setRowSelectionInterval(row, row); } } return Arrays.stream(table.getSelectedRows()) .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0)) .filter(value -> value instanceof EquipmentFacade) .map(value -> (EquipmentFacade) value) .collect(Collectors.toList()); }
Example 6
Source File: EquipInfoTab.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private static List<EquipNode> getMenuTargets(JTable table, MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { if ((row >= 0) && (table.getRowCount() > row)) { table.setRowSelectionInterval(row, row); } } return Arrays.stream(table.getSelectedRows()) .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0)) .filter(value -> value instanceof EquipNode) .map(value -> (EquipNode) value) .collect(Collectors.toList()); }
Example 7
Source File: EquipInfoTab.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private static List<EquipNode> getMenuTargets(JTable table, MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { if ((row >= 0) && (table.getRowCount() > row)) { table.setRowSelectionInterval(row, row); } } return Arrays.stream(table.getSelectedRows()) .mapToObj(selRow -> table.getModel().getValueAt(selRow, 0)) .filter(value -> value instanceof EquipNode) .map(value -> (EquipNode) value) .collect(Collectors.toList()); }
Example 8
Source File: CTracesNodeComponent.java From binnavi with Apache License 2.0 | 6 votes |
/** * Shows a popup menu for a given mouse event. * * @param event The event that triggered the popup menu. */ private void showPopupMenu(final MouseEvent event) { final JTable traceTable = m_tracesPanel.getTracesTable(); final int mouseRow = traceTable.rowAtPoint(event.getPoint()); if (mouseRow != -1) { final int[] rows = traceTable.getSelectedRows(); if (Ints.asList(rows).indexOf(mouseRow) != -1) { traceTable.setRowSelectionInterval(mouseRow, mouseRow); } } // Make sure at least one row is selected final int minIndex = m_tracesPanel.getTracesTable().getSelectionModel().getMinSelectionIndex(); if (minIndex != -1) { final JPopupMenu popupMenu = new CEventListTableMenu( (JFrame) SwingUtilities.getWindowAncestor(CTracesNodeComponent.this), m_tracesPanel.getTracesTable(), m_container.getTraceProvider()); popupMenu.show(m_tracesPanel.getTracesTable(), event.getX(), event.getY()); } }
Example 9
Source File: AnySelectionTableUI.java From wandora with GNU General Public License v3.0 | 6 votes |
@Override public void mousePressed(MouseEvent e) { super.mousePressed(e); if(!SwingUtilities.isLeftMouseButton(e)) { return; } JTable t = getTable(); Point p = e.getPoint(); int row = t.rowAtPoint(p); int column = t.columnAtPoint(p); int rowCount = t.getRowCount(); int columnCount = t.getColumnCount(); if(column < 0 || row < 0 || column >= columnCount || row >= rowCount ) { return; } TableCellEditor tce = t.getCellEditor(); if((tce==null) || (tce.shouldSelectCell(e))) { t.requestFocus(); updateTableSelectionModel(row, column, e.isControlDown(), e.isShiftDown(), false); t.repaint(); } }
Example 10
Source File: DataObjectTransferHandler.java From nextreports-designer with Apache License 2.0 | 5 votes |
@Override public boolean importData(JComponent c, Transferable transferable) { if (!canImport(c, transferable.getTransferDataFlavors())) { return false; } try { if (getDragComponent() != c) { List list = (List) transferable.getTransferData(dataFlavor); JTable table = (JTable) c; DesignerTablePanel.MyTableModel model = ((DesignerTablePanel.MyTableModel) table.getModel()); int insertRow; if (getDropPoint() != null) { insertRow = table.rowAtPoint(getDropPoint()); } else { insertRow = table.getSelectedRow(); } for (int i = 0; i < list.size(); i++) { model.insertRow(insertRow + i, (Vector) list.get(i)); } table.getSelectionModel().clearSelection(); table.getSelectionModel().setSelectionInterval(insertRow, insertRow + list.size() - 1); table.requestFocus(); } return true; } catch (Exception e) { e.printStackTrace(); return false; } }
Example 11
Source File: PacketTableMouseListener.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public void showPopupMenu(MouseEvent e) { JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); //int col = table.columnAtPoint(e.getPoint()); boolean val = !((PacketTableModel) table.getModel()).getIsMarked(row); ((PacketTableModel) table.getModel()).setIsMarked(row, val); table.repaint(); }
Example 12
Source File: UIUtil.java From Astrosoft with GNU General Public License v2.0 | 5 votes |
/** Event source cell of JTable based on mouse position * */ public static Cell getSourceTableCell(MouseEvent e) { JTable table = (JTable) e.getSource(); AstrosoftTableModel model = (AstrosoftTableModel) table.getModel(); int row = table.rowAtPoint(e.getPoint()); int col = table.convertColumnIndexToModel(table.columnAtPoint(e .getPoint())); return new Cell(row, model.getColumn(col)); }
Example 13
Source File: ExperimentTab.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
public void mouseClicked(MouseEvent e) { int fromRow = NO_ROW_SELECTED; JTable table = null; if (showRawBytes.isSelected()) { table = this.table; } else { table = packetTable; } int row = table.rowAtPoint(e.getPoint()); int col = table.columnAtPoint(e.getPoint()); if (e.isShiftDown()) { // from row is the first in the selection. It equals row if we clicked above the current selected row fromRow = table.getSelectedRow(); int n = table.getSelectedRowCount(); if (row == fromRow) fromRow = fromRow + n-1; } if (row >= 0 && col >= 0) { //Log.println("CLICKED ROW: "+row+ " and COL: " + col); displayRow(table, fromRow, row); } }
Example 14
Source File: HealthTab.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
@Override public void mouseClicked(MouseEvent e) { int fromRow = NO_ROW_SELECTED; JTable table; // RT MAX MIN SWITCH if (healthTableToDisplay == DISPLAY_RT) { table = rtTable; } else if (healthTableToDisplay == DISPLAY_MAX) { table = maxTable; } else { table = minTable; } // row is the one we clicked on int row = table.rowAtPoint(e.getPoint()); int col = table.columnAtPoint(e.getPoint()); if (e.isShiftDown()) { // from row is the first in the selection. It equals row if we clicked above the current selected row fromRow = table.getSelectedRow(); int n = table.getSelectedRowCount(); if (row == fromRow) fromRow = fromRow + n-1; } if (row >= 0 && col >= 0) { //Log.println("CLICKED ROW: "+row+ " and COL: " + col); displayRow(table, fromRow, row); } }
Example 15
Source File: DropboxRevisionsTopComponent.java From Open-LaTeX-Studio with MIT License | 5 votes |
private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed if (evt.getClickCount() == 2) { // Resolving which row has been double-clicked Point point = evt.getPoint(); JTable table = (JTable) evt.getSource(); int row = table.rowAtPoint(point); // Finding revision using information from the clicked row Object revisionNumber = table.getValueAt(row, REVISION_COLUMN); if (revisionNumber != null) { loadRevision(revisionNumber.toString()); } } }
Example 16
Source File: CreateAvdVisualPanel1.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { Component comp = e.getComponent(); if (comp instanceof JTable) { JTable table = (JTable) comp; int rowIndex = table.rowAtPoint(e.getPoint()); table.setRowSelectionInterval(rowIndex, rowIndex); editMenu.setEnabled(selectedDevice != null && userDevices.contains(selectedDevice)); deleteMenu.setEnabled(selectedDevice != null && userDevices.contains(selectedDevice)); } popupMenu.show(comp, e.getX(), e.getY()); } }
Example 17
Source File: DataObjectTransferHandler.java From nextreports-designer with Apache License 2.0 | 5 votes |
public void dragOver(DropTargetDragEvent event) { int dropAction = event.getDropAction(); if (canImport && actionSupported(dropAction)) { JTable table = (JTable) event.getDropTargetContext().getComponent(); int row = table.rowAtPoint(event.getLocation()); table.getSelectionModel().setSelectionInterval(row, row); event.acceptDrag(dropAction); } else { event.rejectDrag(); } }
Example 18
Source File: QueryBuilderResultTable.java From netbeans with Apache License 2.0 | 5 votes |
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable)(e.getSource()); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); // Make sure the row where click occurred is selected. if (row != -1) { source.setRowSelectionInterval (row, row); } resultTablePopup.show(e.getComponent(), e.getX(), e.getY()); } }
Example 19
Source File: MenuManager.java From jeveassets with GNU General Public License v2.0 | 4 votes |
private void selectClickedCell(final MouseEvent e) { Object source = e.getSource(); if (source instanceof JTable) { JTable jSelectTable = (JTable) source; Point point = e.getPoint(); if (!jSelectTable.getVisibleRect().contains(point)) { //Ignore clickes outside table return; } int clickedRow = jSelectTable.rowAtPoint(point); int clickedColumn = jSelectTable.columnAtPoint(point); //Rows boolean clickInRowsSelection; if (jSelectTable.getRowSelectionAllowed()) { //clicked in selected rows? clickInRowsSelection = false; int[] selectedRows = jSelectTable.getSelectedRows(); for (int i = 0; i < selectedRows.length; i++) { if (selectedRows[i] == clickedRow) { clickInRowsSelection = true; break; } } } else { //Row selection not allowed - all rows selected clickInRowsSelection = true; } //Column boolean clickInColumnsSelection; if (jSelectTable.getColumnSelectionAllowed()) { //clicked in selected columns? clickInColumnsSelection = false; int[] selectedColumns = jSelectTable.getSelectedColumns(); for (int i = 0; i < selectedColumns.length; i++) { if (selectedColumns[i] == clickedColumn) { clickInColumnsSelection = true; break; } } } else { //Column selection not allowed - all columns selected clickInColumnsSelection = true; } //Clicked outside selection, select clicked cell if ( (!clickInRowsSelection || !clickInColumnsSelection) && clickedRow >= 0 && clickedColumn >= 0) { jSelectTable.setRowSelectionInterval(clickedRow, clickedRow); jSelectTable.setColumnSelectionInterval(clickedColumn, clickedColumn); } } }
Example 20
Source File: TableHelper.java From CodenameOne with GNU General Public License v2.0 | votes |
public static int getFirstVisibleRow(JTable p_Table) { Point p = p_Table.getVisibleRect().getLocation(); return p_Table.rowAtPoint(p); }