Is there a way to update the current DefaultTableModel
on a JTable
? To clarify what I mean I will use some code examples below.
You might declare a JTable like this
DefaultTableModel model = new DefaultTableModel(tableData, tableHeaders)
{
private static final long serialVersionUID = 8785594035471551113L;
@Override
public boolean isCellEditable(int row, int column)
{
return false;
}
};
JTable table = new JTable(model);
panel.add(table);
I am asking if there is a way to do something similar to this
myTable.java
public class myTable extends JTable {
private static final long serialVersionUID = -5819940358496590055L;
public myTable(TableModel dM) {
setModel(dM);
}
public myTable(Object[][] tableData, Object[] columnHeaders) {
this(new DefaultTableModel(tableData, columnHeaders));
}
public void setEditable(boolean b) {
DefaultTableModel model = (DefaultTableModel) this.getModel();
//Do some code here to make the editable or uneditable
setModel(model);
}
}
someJavaFile.java
JTable table = new myTable(tableData, tableHeaders);
table.setEditable(false);
panel.add(table);
I am not asking you to do this for me but I am asking you to aid me in finding a way to update the current DefaultTableModel
.
I appreciate any help
Edit for clarification
I am trying to find a way to manipulate the current DefaultTableModel
on a JTable for things such as whether the table is editable or not as there are no methods which support toggling whether the table is editable after the model has been made. There is only isCellEditable()
.
Why would this be useful?
This would be useful if you were wanting to manipulate the way the table worked with an ActionListener
on a JButton
or something similar