To hide a column from only the view of JTable, i am using the removeColumn()
method. But it throws the exception
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:470)
at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294)
at javax.swing.plaf.basic.BasicTableHeaderUI.paint(BasicTableHeaderUI.java:648)
i think, after removing column from the view, if i modified the model, then this exception pops out. is it because of there is no column in view, while the model is updating the table ?
What is the best way to hide the column in view in JTable ? insteading of setting the sizes to 0
EDIT: The exception is not occuring regularly. it is a random exception. Anyway here is the code:
@Override
protected Object doInBackground() throws Exception {
........
resultDTO=//get data from database
tableModel.setDataVector(resultDTO.getAllRows(), tableModel.getColumnNames());
// hide column
table.removeColumn(table.getColumnModel().getColumn(7));
System.out.println("table column count : " + table.getColumnCount());
System.out.println("model column count : " + tableModel.getColumnCount());
........
.........
}
initial result (with out any data in table, at application startup):
table column count : 7
model column count : 8
after populating data (first running of above method):
table column count : 7
model column count : 8
after few times executing :
table column count : 7
model column count : 8
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:470)
at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294)
at javax.swing.plaf.basic.BasicTableHeaderUI.paint(BasicTableHeaderUI.java:648)
at javax.swing.plaf.synth.SynthTableHeaderUI.paint(SynthTableHeaderUI.java:173)
Some times the above exception occures when i first load the data, and sometimes its not.