Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I come to another solution, since I wanted to reuse default editors… The following class redefines the getColumnClass to have a different answer. As far as I've tested, it works fine, and I can use setDefaultEditor and so on. You can notice that it's possible to enhance this behavior to apply it only on desired columns.</p> <pre><code>public class JXMultiTypeColumnTable extends JXTable { private Map&lt;Integer, Class&lt;?&gt;&gt; viewedClassByColumn = new HashMap&lt;Integer, Class&lt;?&gt;&gt;(); public JXMultiTypeColumnTable(Object[][] rowData, Object[] columnNames) { super(rowData, columnNames); } public JXMultiTypeColumnTable(int numRows, int numColumns) { super(numRows, numColumns); } public JXMultiTypeColumnTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) { super(dm, cm, sm); } public JXMultiTypeColumnTable(TableModel dm, TableColumnModel cm) { super(dm, cm); } public JXMultiTypeColumnTable(TableModel dm) { super(dm); } public JXMultiTypeColumnTable() { } @Override public Class&lt;?&gt; getColumnClass(int column) { Class&lt;?&gt; recordedClass = this.viewedClassByColumn.get(column); if (recordedClass != null) { return recordedClass; } return super.getColumnClass(column); } private void recordViewedClass(int row, int column) { this.viewedClassByColumn.put(column, this.getModel().getValueAt( this.convertRowIndexToModel(row), this.convertColumnIndexToModel(column)) .getClass()); } @Override public TableCellRenderer getCellRenderer(int row, int column) { this.recordViewedClass(row, column); return super.getCellRenderer(row, column); } @Override public TableCellEditor getCellEditor(int row, int column) { this.recordViewedClass(row, column); return super.getCellEditor(row, column); } </code></pre> <p>}</p> <p>N.B. It is possible to extend <code>JTable</code> instead of <code>JXTable</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload