I created a MasterDetail Simple Form
using Netbeans
, and I have a JTable
which is related to the database.
I want to edit a column in this JTable
to make it non-editable.
I Googled about it and this all I can find :
this.masterTable.getColumn("Validation").setEditable(false);
which won't work with me !
setReorderingAllowed() method and set the value as false.
The isCellEditable() method of JTable (or the TableModel) controls whether a cell is editable or not. By default it just return "true". So you can override the method to return a boolean value that is set by your "Modify" button.
If you want to be able to make a table column editable right click on the table and select on Customizers > Table Customizers > Editable and check whatever columns you want to make editable. The same applies to hiding columns.
Override the isCellEditable(...)
method of the TableModel.
DefaultTableModel model = new DefaultTableModel(...)
{
@Override
public boolean isCellEditable(int row, int column)
{
// add your code here
}
}
JTable table = new JTable( model );
Disabling user edits on JTable for multiple columns
JTable table = new JTable(10, 4) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 3 || column==4 || column==5 ? true : false;
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With