@Override public void run() { row = table.convertRowIndexToModel( table.getEditingRow() ); column = table.convertColumnIndexToModel( table.getEditingColumn() ); oldValue = table.getModel().getValueAt(row, column); newValue = null; }
/** * Checks whether the trigger event is allowed to be fired according the particular column model index. * * @return True if trigger is allowed, false otherwise. */ private boolean isTriggerAllowedOnColumn() { boolean allow = false; try { int viewColumnIndex = table.convertColumnIndexToView(modelColumnIndex); if (viewColumnIndex == table.getEditingColumn()) { allow = true; } } catch (IndexOutOfBoundsException e) { allow = false; } return allow; } }
/** * Checks whether the trigger event is allowed to be fired according the particular column model index. * * @return True if trigger is allowed, false otherwise. */ private boolean isTriggerAllowedOnColumn() { boolean allow = false; try { int viewColumnIndex = table.convertColumnIndexToView(modelColumnIndex); if (viewColumnIndex == table.getEditingColumn()) { allow = true; } } catch (IndexOutOfBoundsException e) { allow = false; } return allow; } }
JTable table = new JTable(); table.getEditingColumn(); table.getEditingRow(); table.getEditorComponent();
@Override public void run() { this.row = this.table.convertRowIndexToModel(this.table.getEditingRow()); this.column = this.table.convertColumnIndexToModel(this.table.getEditingColumn()); this.oldValue = this.table.getModel().getValueAt(this.row, this.column); this.newValue = null; } }
public void run() { row = table.convertRowIndexToModel(table.getEditingRow()); column = table.convertColumnIndexToModel(table.getEditingColumn()); oldValue = table.getModel().getValueAt(row, column); newValue = null; }
/** * Stop any editing that is currently being done on the table. This will * save any changes that have already been made. * * @param table the table to stop on editing */ public static void stopTableEditing(JTable table) { if (table.isEditing()) { TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn()); cellEditor.stopCellEditing(); } }
public static void commitChanges(JTable table) { if (table.isEditing()) { String text = ((JTextComponent) table.getEditorComponent()).getText(); table.setValueAt(text, table.getEditingRow(), table.getEditingColumn()); table.getCellEditor().cancelCellEditing(); } }
/** * cancel any editing that is currently being done on the table. * * @param table the table to cancel on editing * @since 3.1 */ public static void cancelEditing(JTable table) { // If a table cell is being edited, we must cancel the editing if (table != null && table.isEditing()) { TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn()); cellEditor.cancelCellEditing(); } }
@Override public void actionPerformed(ActionEvent e) { combo.setSelectedItem(getText()); Component component = getParent().getParent(); if(component instanceof JTable) { JTable table = (JTable)component; if((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) { table.changeSelection(table.getEditingRow(), table.getEditingColumn()-1, false, false); } else { table.changeSelection(table.getEditingRow(), table.getEditingColumn()+1, false, false); } } else { if((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) { transferFocusBackward(); } else { transferFocus(); } } } });
/** * Stops any editing for a given cell on a table. */ public static void stopEditing(JTable table) { if (table == null) { assert (false); return; } if (table.isEditing()) { int row = table.getEditingColumn(); int col = table.getEditingRow(); if (row >= 0 && col >= 0) { javax.swing.CellEditor editor = table.getCellEditor(row, col); editor.stopCellEditing(); } } } }
private void paintCell(final Graphics g, final Rectangle cellRect, final int row, final int column) { if (table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == column) { Component component = table.getEditorComponent(); component.setBounds(cellRect); component.validate(); } else { TableCellRenderer renderer = table.getCellRenderer(row, column); Component component = table.prepareRenderer(renderer, row, column); rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true); } } private void paintCells(final Graphics g, final int rMin, final int rMax, final int cMin, final int cMax) {
private void updateBounds() { if (table == null) { System.err.println("table is null"); return; } if (table.isEditing()) { Rectangle cellRect = table.getCellRect(table.getEditingRow(), table.getEditingColumn(), false); Dimension prefSize = getPreferredSize(); putClientProperty(UPDATE_BOUNDS, Boolean.TRUE); setBounds(getX(), getY(), Math.min(cellRect.width, prefSize.width), Math.max(cellRect.height + prefSize.height, prefSize.height)); putClientProperty(UPDATE_BOUNDS, Boolean.FALSE); validate(); } }
private void paintCell(Graphics g, Rectangle cellRect, int row, int column) { if (table.isEditing() && table.getEditingRow()==row && table.getEditingColumn()==column) { Component component = table.getEditorComponent(); component.setBounds(cellRect); component.validate(); } else { TableCellRenderer renderer = table.getCellRenderer(row, column); Component component = table.prepareRenderer(renderer, row, column); rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true); } }
public void actionPerformed(ActionEvent e) { if (grid.isEditing()) { TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn()); cellEditor.stopCellEditing(); } tableModel.addRow(defaultValues); tableModel.fireTableDataChanged(); // Enable DELETE (which may already be enabled, but it won't hurt) deleteRowButton.setEnabled(true); // Highlight (select) the appropriate row. int rowToSelect = tableModel.getRowCount() - 1; if (rowToSelect < grid.getRowCount()) { grid.setRowSelectionInterval(rowToSelect, rowToSelect); } sender.updateUI(); } }
public void actionPerformed(ActionEvent e) { if (grid.isEditing()) { TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn()); cellEditor.stopCellEditing(); } tableModel.addRow(defaultValues); tableModel.fireTableDataChanged(); // Enable DELETE (which may already be enabled, but it won't hurt) deleteRowButton.setEnabled(true); // Highlight (select) the appropriate row. int rowToSelect = tableModel.getRowCount() - 1; if (rowToSelect < grid.getRowCount()) { grid.setRowSelectionInterval(rowToSelect, rowToSelect); } sender.updateUI(); } }
private void paintCell(Graphics g, Rectangle cellRect, int row, int column, int dx, int dy) { if(table.isEditing() && table.getEditingRow()==row && table.getEditingColumn()==column) { Component component=table.getEditorComponent(); component.setBounds(cellRect); component.validate(); } else { TableCellRenderer renderer=table.getCellRenderer(row, column); Component component=table.prepareRenderer(renderer, row, column); rendererPane.paintComponent(g, component, table, cellRect.x+dx, cellRect.y+dy, cellRect.width-1, cellRect.height-1, true); } }
public void actionPerformed(ActionEvent e) { if (grid.isEditing()) { TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn()); cellEditor.stopCellEditing(); } final int selectedRow = grid.getSelectedRow(); if (tableModel.getRowCount() == 0 || selectedRow < 0) { return; } tableModel.addRow(tableModel.getRowData(selectedRow)); tableModel.fireTableDataChanged(); // Enable DELETE (which may already be enabled, but it won't hurt) deleteRowButton.setEnabled(true); // Highlight (select) the appropriate row. int rowToSelect = selectedRow + 1; grid.setRowSelectionInterval(rowToSelect, rowToSelect); sender.updateUI(); } }
public void actionPerformed(ActionEvent e) { if (grid.isEditing()) { TableCellEditor cellEditor = grid.getCellEditor(grid.getEditingRow(), grid.getEditingColumn()); cellEditor.stopCellEditing(); } final int selectedRow = grid.getSelectedRow(); if (tableModel.getRowCount() == 0 || selectedRow < 0) { return; } tableModel.addRow(tableModel.getRowData(selectedRow)); tableModel.fireTableDataChanged(); // Enable DELETE (which may already be enabled, but it won't hurt) deleteRowButton.setEnabled(true); // Highlight (select) the appropriate row. int rowToSelect = selectedRow + 1; grid.setRowSelectionInterval(rowToSelect, rowToSelect); sender.updateUI(); } }
@Override public void focusLost(FocusEvent e) { final int editingRow = table.getEditingRow(); final int editingColumn = table.getEditingColumn(); CellEditor ce = null; if (editingRow != -1 && editingColumn != -1) { ce = table.getCellEditor(editingRow,editingColumn); } Component editor = table.getEditorComponent(); if(ce != null && (editor == null || editor != e.getOppositeComponent())) { ce.stopCellEditing(); } else if(editor != null) { editor.addFocusListener(this); } this.firePropertyChange(); }