JTable
cells[1]
DefaultCellEditor
class only allows to use checkbox, textfields, or comboboxExtendedCellEditor
:ExtendedCellEditor
classGenericEditor
constructorExtendedCellEditor
class has several specific constructors, allowing to use more components that allowed in the DefaultCellEditor
class:DefaultTableModel model = new DefaultTableModel(); model.addColumn("Value"); Vector<Object> v = new Vector<>(); v.add(true); model.addRow(v); ExtendedEditorTable table = new ExtendedEditorTable(model); table.addEditor(0, 0, new ExtendedCellEditor(new JCheckBox()));
public class MyGenericEditor extends AbstractGenericEditor<MyGenericPanel> { public MyGenericEditor(JTable table) { super(table); editor = new TestGenericPanel(); } public Object getValue() { return editor.getValue(); } public void setValue(Object value) { editor.setValue((Boolean) value); } public class MyGenericPanel extends JPanel { private final JCheckBox cb = new JCheckBox("CheckBox"); private TestGenericPanel() { this.setLayout(new BorderLayout()); this.add(cb, BorderLayout.CENTER); } public boolean getValue() { return cb.isSelected(); } public int getClickCountToStart() { return 2; } public void setValue(boolean b) { cb.setSelected(b); } } }And to integrate this component in the table:
DefaultTableModel model = new DefaultTableModel(); model.addColumn("Value"); Vector<Object> v = new Vector<>(); v.add(true); model.addRow(v); v = new Vector<>(); v.add(1); model.addRow(v); ExtendedEditorTable table = new ExtendedEditorTable(model); TestGenericEditor editor = new TestGenericEditor(table); table.addEditor(0, 0, new ExtendedCellEditor(editor)); table.addOpenEditorListener(0, 0, editor.getAppproveListener());
DefaultCellEditor
class only allows to use checkbox, textfields, or comboboxCopyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences