Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java Tip 137: Manage distributed JTables

Efficiently display huge JTables using distributed caching TableModels

  • Print
  • Feedback

Page 3 of 3

int[] sort(int sortColumn, boolean ascending, int[] selectedRows) throws Exception

Along with the sort column and ascending flag, you must feed in the selected row indexes and then return the sorted data's corresponding indexes. Three more methods are required to implement sorting fully: setSelectedRowsAndColumns(), getSelectedRows(), and getSelectedColumns(). These methods keep the selections in sync between the client and server.

Figure 3 shows a sequence diagram for the sorting and selection process.

Figure 3. A sequence diagram shows a distributed JTable's sorting process. Click on thumbnail to view full-size image.

Simplified table managment

I've described a method that allows a large table to quickly display without waiting for a bulk data download. If a user scrolls down the whole table, all the data must download sooner or later. But there is always a balance between immediately downloading all data and taking the performance hit later. This tip's method provides the following advantages:

  • The table component quickly displays
  • The client program does not use much memory since the client side only stores a small amount of data
  • A table or spreadsheet's rich user interface is maintained
  • Resources are not wasted on data downloads when the user is uninterested in the results below a certain row


The associated source code provides this process's proof-of-concept implementation. In that demo, a client containing a read-only sortable JTable of 200,000 rows retrieves data from a servlet as XML and stores it in a DistributedTableModel. You can easily extend this demo to implement single cell selection, data editing, and more.

About the author

Jeremy Dickson has been writing Java code for more than five years in the domain of bioinformatics and life science. He has worked on everything from JavaBean components for displaying genetic maps to Enterprise JavaBean-based server-side platforms for project management.

Read more about Core Java in JavaWorld's Core Java section.

  • Print
  • Feedback

Resources