Java Code Examples for javax.swing.JTable#columnAtPoint()
The following examples show how to use
javax.swing.JTable#columnAtPoint() .
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: 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 2
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 3
Source File: QueryBuilderInputTable.java From netbeans with Apache License 2.0 | 6 votes |
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable)(e.getSource()); if ( ! source.isEnabled () ) return; _inputTablePopupRow = source.rowAtPoint(new Point (e.getX(), e.getY())); _inputTablePopupColumn = source.columnAtPoint(new Point (e.getX(), e.getY())); // Make sure the row where click occurred is selected. if (_inputTablePopupRow != -1) { source.setRowSelectionInterval (_inputTablePopupRow, _inputTablePopupRow); } // if ( _inputTablePopupColumn != Criteria_COLUMN ) // { // // return without showing popup // return; // } _inputTablePopup.show(e.getComponent(), e.getX(), e.getY()); } }
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: 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 6
Source File: DeckGamesJTable.java From magarena with GNU General Public License v3.0 | 6 votes |
@Override public void mouseMoved(MouseEvent e) { JTable aTable = (JTable) e.getSource(); int mCol = aTable.columnAtPoint(e.getPoint()); int mRow = aTable.rowAtPoint(e.getPoint()); if (mCol != lastMCol || mRow != lastMRow) { lastMCol = mCol; lastMRow = mRow; if (mCol == 4) { aTable.repaint(); MouseHelper.showHandCursor(aTable); } else { aTable.repaint(); MouseHelper.showDefaultCursor(aTable); } } }
Example 7
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 8
Source File: BotCWTableModel.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Called when user clicks on the table. * * @param e Mouse event. */ public void mouseClicked(MouseEvent e) { if (e == null) { return; } // Extract information int count = e.getClickCount(); JTable target = (JTable) e.getSource(); int row = target.rowAtPoint(e.getPoint()); int column = target.columnAtPoint(e.getPoint()); int modelRow = target.convertRowIndexToModel(row); int modelColumn = target.convertColumnIndexToModel(column); // Act depending on the button clicked switch (e.getButton()) { case MouseEvent.BUTTON1: cellClickedLeft(count, modelRow, modelColumn); break; case MouseEvent.BUTTON3: cellClickedRight(target, e.getPoint()); break; } }
Example 9
Source File: AnySelectionTableUI.java From wandora with GNU General Public License v3.0 | 5 votes |
@Override public void mouseDragged(MouseEvent e) { super.mouseDragged(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) { t.requestFocus(); updateTableSelectionModel(row, column, e.isControlDown(), !e.isShiftDown(), true); t.repaint(); } }
Example 10
Source File: DeckCellRenderer.java From magarena with GNU General Public License v3.0 | 5 votes |
private boolean isMouseOverCell(JTable table, int row, int col) { Point mp = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(mp, table); int mRow = table.rowAtPoint(mp); int mCol = table.columnAtPoint(mp); return row == mRow && col == mCol; }
Example 11
Source File: PlayerCellRenderer.java From magarena with GNU General Public License v3.0 | 5 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String profileGUID = (String)value; PlayerProfile player = PlayerProfiles.getPlayerProfiles().get(profileGUID); boolean isTempPlayer = player == null; final JLabel lbl = new JLabel(!isTempPlayer ? player.getPlayerName() : ""); lbl.setOpaque(true); if (isSelected) { lbl.setForeground(table.getSelectionForeground()); lbl.setBackground(table.getSelectionBackground()); } else { lbl.setForeground(table.getForeground()); lbl.setBackground(table.getBackground()); } if (isTempPlayer) { lbl.setForeground(Color.GRAY); } else { 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 12
Source File: PageListMouseListener.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * @param e Event. * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if ((!e.isConsumed()) && (e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) { if (e.getSource() instanceof JTable) { JTable table = (JTable) e.getSource(); if (table.getModel() instanceof PageListTableModel) { PageListTableModel model = (PageListTableModel) table.getModel(); int column = table.columnAtPoint(e.getPoint()); int row = table.rowAtPoint(e.getPoint()); if ((column >= 0) && (row >= 0)) { row = Utilities.convertRowIndexToModel(table, row); Page page = model.getPage(row); if (Boolean.TRUE.equals(page.isDisambiguationPage())) { Controller.runDisambiguationAnalysis(page.getTitle(), page.getWikipedia()); } else { Controller.runFullAnalysis(page.getTitle(), null, page.getWikipedia()); } e.consume(); } } } } super.mouseClicked(e); }
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: TableCellDrag.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@Override public void mouseDragged(MouseEvent e) { if (e.isAltDown() && startLocation != null) { isInDragOperation = true; JTable t = (JTable) e.getSource(); int selRow = t.rowAtPoint(e.getPoint()); int selColumn = t.columnAtPoint(e.getPoint()); if (selRow != -1 && selColumn != -1) { rowsRColumns.add(new Integer[]{selRow, selColumn}); } } else { isInDragOperation = false; } }
Example 16
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 17
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 18
Source File: PluginManagerDialog.java From sc2gears with Apache License 2.0 | 2 votes |
/** * Tells if the specified event happened on the home page link cell. * @param detailsTable reference to the details table * @param event event to examine * @return true if the event happened on the home page link cell; false otherwise */ private static boolean isEventOnHomePageLinkCell( final JTable detailsTable, final MouseEvent event ) { final Point point = event.getPoint(); return detailsTable.rowAtPoint( point ) == 6 && detailsTable.columnAtPoint( point ) == 1; }