I seem to have an anoying problem. The problem is that when i try to insert data in to a JTable using a JButton the JTable wont update until i resize the frame manually, sometimes this does not work. Though the same code works perfectly on some computers, dont know if it is the JDK version or not. Anyways heres the code:
in your actionListener you create a new JTable, but don't do anything with it.
the fact it works on some computers indicates that in your real code you probably remove the old table from the scrollpane, then add the new one. in this case it should be scrollPane.revalidate(); repaint();//sometimes required, sometimes not, safest to have it
you don't really need to create a new JTable, then remove/add, just change the tableModel
(table will need to be made final, or moved so it is a class field - not local)
//JTable table = new JTable(data, columnNames); //validate(); table.setModel(new javax.swing.table.DefaultTableModel(data, columnNames));
Joined: Nov 05, 2006
Thanks alot Michael that has helped alot, i think im on the right path using table models rather than adding data direct to the jtable.