Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable Paging

 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I intend to use the following paging model implemented with the table when handling large amounts of data.

http://www.java2s.com/Code/Java/Swing-JFC/AquickapplicationthatdemonstratesthePagingModel.htm

The table shows only 100 entries at a time in the table.The next or previous 100 entries are got by clicking the corner buttons("Down" or "Up" buttons) in the scroll pane.

I want the table to behave in a different way ,without this corner buttons.

[1]The scrollbars should look in a way that the Table is filled with all the data's.Can we mimic the Tablemodel to do something like this?

[2]The table should be filled with the next 100 or previous 100 entries while scrolling up & down the table, either using the scroll bar,the arrow buttons in the scroll bar or when he selects a row in the table and uses the up,down arrow keys of the keyboard.

For the end user, the behaviour of the Table is as if the whole list of data is loaded into the Table.

Is this possible or what could be done to achieve something close to this...What shoule be changed in the PagingModel.Java file

Thanks
P
 
Krishnamoorthy Vuyala Muralidharan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Please take a look at the below blog which addresses your issue:

http://looksgoodworkswell.blogspot.com/2005/06/death-to-paging-rico-livegrid-released.html

Hope this helps.

Kind regards
Kris
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The table uses a TableModel for all of this:
- getRowCount() for the number of rows, so also for the scrollbars
- getValueAt(int row, int column) for the data of a specific cell

Now the default table model implementations usually store all data all the time, but nothing prevents you from writing your own implementation instead that only retrieves data as necessary.
Best approach is to extend AbstractTableModel so you won't have to code the events that need to be raised. All you need to do is call the right fire* method.
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arun Sanker:
paging model implemented with the table when handling large amounts of data.

The table shows only 100 entries at a time in the table.The next or previous 100 entries are got by clicking the corner buttons("Down" or "Up" buttons) in the scroll pane.

I want the table to behave in a different way ,without this corner buttons.

[1]The scrollbars should look in a way that the Table is filled with all the data's.Can we mimic the Tablemodel to do something like this?


When someone asked this a couple years ago I answered that JTable is already sort of
designed to do this. By that I meant that your table can have a million rows, but your table model will only be asked about the rows that it needs to display on screen, not all million rows.

I don't think people understood what I was getting at, though, so I'll put my money where my mouth is:



If you run this, whip the scroll bar quickly down to the 800,000th row or so, and watch the console, you'll see that it doesn't have to load all 800,000 intervening rows of data. It only has to load a couple thousand rows of data to do that, depending on how fast you drag the scroll thumb.

If you replace new JScrollPane(tab) with LazyViewport.createLazyScrollPaneFor(tab) in main it doesn't even have to load that many, but this post is too long already. I'll save the implementation of LazyViewport for another post.
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Cole:
If you replace new JScrollPane(tab) with LazyViewport.createLazyScrollPaneFor(tab) in main it doesn't even have to load that many, but this post is too long already. I'll save the implementation of LazyViewport for another post.


I forgot that I owed a post on LazyViewport. Sorry about that.

I've explained it at http://bitguru.wordpress.com/2008/01/07/lazyviewport/
 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Krishnamoorthy,Rob,Brian.....

Thanks a lot....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic