Swing JTable Scrolling not working properly

Posted by Marko on Stack Overflow See other posts from Stack Overflow or by Marko
Published on 2012-10-21T18:21:13Z Indexed on 2012/10/21 23:00 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

I'm doing an application, which uses Swing JTable. I used drag and drop in NetBeans, to add the JTable. When I add the JTable, JScrollPane is added automaticly.

All the look is done with drag and drop. By pressing the first button, I set the number of rows in the table. This is the code to set my DataModel

int size = 50;
String[] colNames = {"Indeks", "Ime", "Priimek", "Drzava"};
DefaultTableModel model = new DefaultTableModel(size, colNames.length);
model.setColumnIdentifiers(colNames);
table.setModel(model);

So if the size is, let's say 10, it works OK, since there is no scroll bar. When I add 50 empty rows, when trying to scroll for 5 seconds, it doesn't work properly and crashes in some time.

I added the picture, for better understanding (this is what happens to the rows when I scroll up and down for a while).

swing row

What could be wrong? Am I not using the DataModel as it is supposed to be used, should I .revalidate() or .repaint() the JTable?

© Stack Overflow or respective owner

Related posts about java

Related posts about swing