tags:

views:

662

answers:

2

Hi all,

I need to build a table from SQL select result set. I want to add some paging functionality to the table because the result set can be very large. There was many discussions how to do the paging at the SQL level. But how to implement the paging at the GUI level? I have two ideas:

  1. Do the paging in a web UI style - for example google search result paging;
  2. "Excel style" - the scroll pane where the table resides expands as user scrolls down.

The second one looks nicer but complex to implement. When to do SQL select for a next chunk of data so that a user haven't wait for it. There shoul'd be some "read ahead" logic? What will happen if user srolls quite quickly? What to do with rows that aren't visible any more to have constant memory usage? Maybe there is allready such a table component or good examples? Or maybe this good looking table functionality is unworthy of efforts to implement it?

Thanks for your ideas, Marius

+1  A: 

You could do everything directly into your TableModel, there is no need to change something in the UI(well you migh show something in the UI - a status - but you don't need to change how JTable renders itself).

Just implement a JDBCTableModel which will have :

  • count the results and return this value as getRowCount().
  • have a background thread which brings page X(row X to row X + page_size) in memory
  • if the view(JTable) asks for a row which is not there(page not loaded) show a message "Loading data..." somewhere in left or rigth top corner and return empty cells.

Paging doesn't makes sense for a Swing application, it was invented before the current fancy AJAX libraries could implement table scrolling(see http://www.ext-livegrid.com/).

adrian.tarau
Thanks for your responce. I found a very good example of TableModel implemented in a similar way: http://www.coderanch.com/t/345383/Swing-AWT-SWT-JFace/java/JTable-Paging
yes, something like that :)
adrian.tarau
A: 

The people who have built paging tables for AJAX libraries have obviously thought about this a lot, so you may be able to learn from them if you can't find something already built. Since you are using Java, note that you can find paging tables written in Java for GWT. See these SO threads:

http://stackoverflow.com/questions/231407/gwt-paging-widget

http://stackoverflow.com/questions/335602/best-pageable-table-implementation-in-gwt

The ideas (and much of the code) for your implemenation may be found in the open source projects mentioned.

Glenn