Thanks for the EditDisable example!,
August 5, 2009 at 3:34 AM
[code=java]Thanks a lot for your clear example how to set the isCellEditable property of a JTable.
I just found out how to do this in Neatbeans: - go to the visual "Design" modus - click on your JTable, and check out its properties - in the "Code" tab go to "Custom Create Code" and add the following lines: new javax.swing.JTable() { public boolean isCellEditable(int rowIndex, int colIndex) { Object isEditable = getClientProperty("isEditable"); if (isEditable == null) { return false; } else { return (Boolean) isEditable; } }; }
- add a JToggleButton and add an Action Event with the following code: if (jToggleButton1.isSelected()) { jTable1.putClientProperty("isEditable", Boolean.TRUE); } else { jTable1.putClientProperty("isEditable", Boolean.FALSE); }
Now your table will be uneditable by default, but when you click on your toggle button, editing will be enabled. Mutatis mutandis when you click on that button again, obviously.
Once again, thanks! I'm just a Java newbie, and examples like this one do a lot to get me on track.