Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes Problem with JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with JTable" Watch "Problem with JTable" New topic
Author

Problem with JTable

Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
Hi guys,

I am facing some problem here from last two days, and not getting a way to solve it properly.

Problem Description:
I have a file which contains thousands of records, i want to show all those records in JTable, caching them all is a bad thing, since i could run in to OutOfMemory issue. so i thought of using pagination (did it successfully though) but the pagination with next and previous button is not a very user-friendly approach, so i thought of changing the vertical scroll bar behaviour to reflect pagination internally.
Meaning:
User will be given an illusion that Table contains all thousands of records but in reality only those records will be kept in memory which is visible to user. On slidding the Vertical scroll Bar knob up and down will eventually controll the fetching of records from file.

I have created a sample program for it, but i am not able to get it working properly, Any help on this , would be highly appreciated.

Files i have written is as follows:
1. OneLinerFileWriter.java (for testing purpose)
2. OneLinerFileReader.java (for testing purpose)
3. CustomTableModel.java
4. TableFrame.java

Here are the codes for the same:










Can someone please guide me through this?

regards
Akhil


-------------------------------<br />you can't move ahead, unless you try for it.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
I ran your log.txt up to 10000 lines and this seems to work okay.
Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
Thanks craig.
That seems to work fine, but again, i was achieving the same thing using previous and next button. which was working all fine.
Probalem:
However, i want to handle fetching of records by scrolling the knob down or just clicking on default up and down arrows of vertical scroll bar.
no radio buttons no previous next buttons anywhere with the table. just a message label at top of the table, where it keeps displaying, current record numbers shown to the user.
Can you please show me an example where you just scroll the knob down and it fetches next set of records (if currently visible rows are say, 1-15, then it should fetch records from 16-30 and show it to the user), need to control the unit increment, as well as block increments of the knob.

this way if user, slides the knob to the extreme bottom, he should be able to see actual records in that range from the file(say, file contains 10000 records, then on scrolling to the bottom, will fetch records 9985 - 10,000).
similar is applicable to moving up. so basically i want to do following things. which i am not able to do even with so many tries.

1. Calculate the initial JTable rows, which are visible to the user (row height is assumed to be same for all the rows.)

2. Displaying scroll bar knob size such that, giving a feel to user that, all records are present in table currently. but fetch and display only that much records which are visible to the user.

3. Identifying how down the user has actually moved the slider knob (block increment scenario) and fetching the records within that range, example, if initially, rows displayed are 1 to 20, then on scrolling the knob down say, 40 rows scrolled, then the current rows visible to the user should be 40 to 60.

I am completely, screwed up here.... any help form your side will be a great support craig.

regards,
Akhil
Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
Can someone please....help me out here........
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
I copied and ran the code you posted above. It seemed to scroll okay when holding a
scrollBar button but throws exceptions when I click on the scrollBar track. The number
sequences also seem to be off by the table row size. I don't think I could do what you are
asking for. The code I posted is the closest I can come to it.
Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
NO problem craig...

Thanks for replies.

hey anyways...
here's my version of code with pagination......i was also not able to make it behave in a way i was asking above.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with JTable