Forums Register Login

JTable repaint issue

+Pie Number of slices to send: Send


The above code displays a Vector of 20 employees in JTable , used a SimpleTableModel which extends from AbstractTableModel....
i am tryin to do 2 things with JTable : 1st is Paging which works smoothly....

Issue with the above code is :
When i search employee on the basis of firstName the the result is not displayed in table smoothly... it takes some time to refresh on 1st time on subsequent search result is not displayed

I have used Hibernate classes to get all records, which i store in a vector the all search is done on employee records in this Vector

Any help would be greatly appreciated..
1
+Pie Number of slices to send: Send
When changing data in a JTable, you definitely should not create a new instance of JTable. I've reviewed your code only casually, but you seem to load all rows into memory. Several valid approaches exist in this case:

1) You can create a new table model from scratch (as you do now), but instead of creating a new JTable for it, set it to the existing JTable using the setModel method. It is quite straightforward to do this in your code.

2) Update the table model in your code and advertise the change to the table using proper fireTable... methods (note: you must call these methods on the Event Dispatch Thread).

3) Add a row filter to the table. This filter will simply hide the rows that do not match your criteria, you'll just have to put all rows into the table model. Filter could be used to perform the pagination too, only it does not look like much elegant solution. If you decided not to have all data in memory at once, this would have to be reworked.

All of these approaches are well covered in tutorials. These tutorials helped me immensely when I was starting with Swing, especially JTable.

Note: the way you "refresh" the table in the refreshTable method differs slightly from the search method, if you look closely. I assume this is why it behaves differently. However, changing the whole table is incorrect and must be avoided.

Another note: some of your SwingWorkers seem to be designed incorrectly. The first SwingWorker modifies the items Vector, but this instance (items) is passed to the JComboBox. This is not thread-safe - you're modifying data you've passed to a Swing component from a background thread. Correct way would be to construct a new instance of Vector in the background thread and (in the done() method) wrap it in the DefaultComboBoxModel which would then be set to the JComboBox using setModel().
+Pie Number of slices to send: Send
Thanks a ton martin....
+Pie Number of slices to send: Send


I have made a few changes to my previous code Pagination was smooth, Searching goes in smooth too.
Still got a issue here , i display 20 records in table while searching if <=20 records are returned for particular employee firstname then it works ok otherwise JVM goes

Any help would be greatly appreciated..
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2558 times.
Similar Threads
TableRowSorter issue
Printing invicible JTable with Column removed - JTable.PrintMode.FIT_WIDTH problem
Problem with Thread..
Change Text for JButton rendered in a JTable
Problem with JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:03:07.