Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your solution seems awfully complicated for something that looks quite simple. You actually only have two different CellEditor which are both based on a JComboBox.</p> <p>So, a simpler solution would be to extend <code>DefaultCellEditor</code> with a <code>JComboBox</code> and override getTableCellEditorComponent(), depending on which row you are on, you update the <code>JComboBox</code> with the appropriate model and you return the call to <code>super</code>.</p> <p>Eventually, you set this cell editor on all your columns of the table.</p> <p><em>Also consider following Java coding conventions (variables and methods starts with a lower case letter, classes starts with an upper case letter, etc...)</em></p> <p>EDIT:</p> <pre><code> class MyTableCellEditor extends DefaultCellEditor { private DefaultCellEditor defaultEditor; private DefaultComboBoxModel nudaModel = new DefaultComboBoxModel(new String[] { "N", "U", "D", "A" }); private DefaultComboBoxModel nahxpModel = new DefaultComboBoxModel(new String[] { "N", "A", "H", "X", "P" }); public MyTableCellEditor() { super(new JComboBox()); defaultEditor = new DefaultCellEditor(new JTextField()); } private JComboBox getComboBox() { return (JComboBox) editorComponent; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { Membership top = _Memberships.get(column); Membership side = _Memberships.get(row); if (side.getId() == top.getId() &amp;&amp; side.isEft() &amp;&amp; top.isEft()) { return defaultEditor.getTableCellEditorComponent(table, value, isSelected, row, column); } else if (side.getId() != top.getId() &amp;&amp; side.isEft() &amp;&amp; top.isEft()) { getComboBox().setModel(nudaModel); } else { getComboBox().setModel(nahxpModel); } return super.getTableCellEditorComponent(table, NUHPADX(side.getId(), top.getId()), isSelected, row, column); } } </code></pre> <p>And here is implementation of what your TableModel could look like:</p> <pre><code> class MyDataModel extends AbstractTableModel{ @Override public int getRowCount() { return _Memberships.size(); } @Override public int getColumnCount() { return _Memberships.size(); } @Override public String getColumnName(int column) { // Here feel free to return the appropriate column names. return super.getColumnName(column); } @Override public Object getValueAt(int row, int column) { return NUHPADX(_Memberships.get(row).getId(), _Memberships.get(column).getId()); } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { // Here you can do whatever you want to say that is editable or not // If it is editable, you need to override setValueAt return true; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { // Here you need to implement the update of your model } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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