Search in sources :

Example 1 with AbstractTableModel

use of com.revolsys.swing.table.AbstractTableModel in project com.revolsys.open by revolsys.

the class BaseTableCellEditor method getTableCellEditorComponent.

@SuppressWarnings("rawtypes")
@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, int rowIndex, int columnIndex) {
    if (table instanceof JXTable) {
        final JXTable jxTable = (JXTable) table;
        rowIndex = jxTable.convertRowIndexToModel(rowIndex);
        columnIndex = jxTable.convertColumnIndexToModel(columnIndex);
    }
    final AbstractTableModel model = (AbstractTableModel) table.getModel();
    this.editorComponent = model.getEditorField(rowIndex, columnIndex, value);
    if (this.editorComponent instanceof JTextField) {
        final JTextField textField = (JTextField) this.editorComponent;
        textField.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(WebColors.LightSteelBlue), BorderFactory.createEmptyBorder(1, 2, 1, 2)));
    }
    this.editorComponent.setOpaque(false);
    SwingUtil.setFieldValue(this.editorComponent, value);
    this.rowIndex = rowIndex;
    this.columnIndex = columnIndex;
    this.editorComponent.addKeyListener(this);
    this.editorComponent.addMouseListener(this.mouseListeners);
    if (this.editorComponent instanceof JComboBox) {
        final JComboBox comboBox = (JComboBox) this.editorComponent;
        final ComboBoxEditor editor = comboBox.getEditor();
        final Component comboEditorComponent = editor.getEditorComponent();
        comboEditorComponent.addKeyListener(this);
        comboEditorComponent.addMouseListener(this.mouseListeners);
    }
    return this.editorComponent;
}
Also used : JXTable(org.jdesktop.swingx.JXTable) JComboBox(javax.swing.JComboBox) AbstractTableModel(com.revolsys.swing.table.AbstractTableModel) JTextField(javax.swing.JTextField) JComponent(javax.swing.JComponent) Component(java.awt.Component) ComboBoxEditor(javax.swing.ComboBoxEditor)

Example 2 with AbstractTableModel

use of com.revolsys.swing.table.AbstractTableModel in project com.revolsys.open by revolsys.

the class ColorTableCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
    final AbstractTableModel tableModel = (AbstractTableModel) table.getModel();
    this.colorChooser.setColor((Color) value);
    this.colorChooser.setVisible(true);
    final JDialog dialog = JColorChooser.createDialog(table, "Select Color", true, this.colorChooser, e -> tableModel.setValueUndo(this.colorChooser.getColor(), row, column), null);
    dialog.setVisible(true);
    return null;
}
Also used : AbstractTableModel(com.revolsys.swing.table.AbstractTableModel) JDialog(javax.swing.JDialog)

Aggregations

AbstractTableModel (com.revolsys.swing.table.AbstractTableModel)2 Component (java.awt.Component)1 ComboBoxEditor (javax.swing.ComboBoxEditor)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JDialog (javax.swing.JDialog)1 JTextField (javax.swing.JTextField)1 JXTable (org.jdesktop.swingx.JXTable)1