Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is, you <code>isCellEditable</code> method is using a single dimension array (which is okay to do if that's what you want it to do)</p> <pre><code> @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } </code></pre> <p>This basically says, that for all the cells in a given <code>column</code> that they should be editable or not.</p> <p>If you want make an individual cell editable/uneditable, you need to determine if the combination of <code>row</code> and <code>column</code> makes the cell editable/uneditable, not just the <code>column</code></p> <p><strong>Updated with simple example</strong></p> <p>This is a SIMPLE example of the concept. Personally, I wouldn't use a 2D array for this because it becomes to difficult to manage with dynamically table models...</p> <p><img src="https://i.stack.imgur.com/Qxe75.png" alt="enter image description here"></p> <pre><code>import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableModel; public class TestTable { public static void main(String[] args) { new TestTable(); } public TestTable() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } MyTableModel model = new MyTableModel(); JTable table = new JTable(model); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(table)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } public class MyTableModel extends DefaultTableModel { public MyTableModel() { super(new Object[][]{ {"Item ID", ""}, {"Radius", 0}, {"Center", 0}, {"Mass", 0} }, new String[]{ "Property", "Value" }); } Class[] types = new Class[]{ String.class, Object.class }; boolean[][] canEdit = new boolean[][]{ {false, false}, {false, true}, {true, true}, {true, false}, }; @Override public Class getColumnClass(int columnIndex) { return types[columnIndex]; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[rowIndex][columnIndex]; } } } </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. This table or related slice is empty.
    1. 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