Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where to start with a scrollable data grid?

 
Corrie L Sherone
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Not sure if this the right area for this question, but here goes ...)

I'm looking for advice on creating a scrollable data grid.

In a nutshell, I want to display the total sales for various groups, over a large date range. Think of scrolling horizontally in an Excel spreadsheet, except each column (A,B,C...) would represent a date. Scrolling right displays future dates (9/27,9/28/,...) and scrolling left displays past dates (9/22, 9/21,...).



My problem is the date ranges will be large and dynamic, anywhere from a month to three years. So I'm not sure what type of component I should be looking for... Initially I thought of JTable but it doesn't seem suited for this type of "infinite" scrolling (for lack of a better term). Or maybe I'm just misunderstanding how it might work.

I'm not looking for code, just ideas on what components I should be looking at. Then I can go read the API's on my own.

Any suggestions or hints would be greatly appreciated!
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would go with JTable too, since it's designed to display data in a grid format.

But I agree with you that the plain-vanilla idea of JTable doesn't fit well with your design. So I wouldn't implement it as a JTable with several thousand columns. What I would do would be to create a JTable with a fixed, small, number of columns, where "small" means "whatever fits nicely into one screen". Let's call it 10 just for argument.

Initializing the table would fill in the 10 columns with data for the 10 most recent days (or whatever makes sense for your application). That would include the column headings as well. Then clicking the "scroll 1 column left" button would move columns 0-8 into columns 1-9 and fill in column 0 with data for the previous day. So as you'll see, the current day disappears and now the 10 days before that are visible. And clicking the "scroll 1 screen left" button would refill the table for the previous 10 days. Hope that makes sense... normally a scroller has a button at the end which scrolls one row and a bar which, if you click in it, scrolls a whole page. That's what I meant by those two "buttons".

And if you had a "Back 1 year" button, you would just identify the 10 days which were 1 year ago and fill the table with data for those days. I expect your design would include something like that, rather than making the user click dozens or hundreds of times to get over to the right time frame.
 
Corrie L Sherone
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Then clicking the "scroll 1 column left" button would move columns 0-8 into columns 1-9 and fill in column 0 with data for the previous day...


Yes, that makes complete sense. I knew there had to be a smarter way than creating a 'gazillion columns.

Paul Clapham wrote:
I expect your design would include something like that, rather than making the user click dozens or hundreds of times to get over to the right time frame.


Definitely. I just needed to map out the basic concept first. Then move on to bells and whistles.

I appreciate the response. Now I have good idea where start :)
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirement (and Paul's solution!) sounds just like the action of the vertical scrollbar on a Google Calendar widget (gadget?) as used in Google Sites. Maybe you could get some ideas from that.

Off the top of my head, I think I would add a AdjustmentListener to the horizontal scrollbar of the JTable's enclosing JScrollPane and initially add columns to the left or right when the scrollbar's value approached min or (max - extent). At a certain threshold (probably about 3X scrollpane width's worth), I would remove columns from the other end of the scale. Not sure if that makes sense in your context though.

Make sure you setAutoResizeMode to AUTO_RESIZE_OFF. You're probably familiar with this, but I mention it because that's something I commonly forget about and have to go back and add after a trial run
 
Corrie L Sherone
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Well I'm pleased to say I got Paul's suggestion up and running and my 1st "rough" draft is working well. So thanks again Paul!)

Darryl Burke wrote:add columns to the left or right when the scrollbar's value approached min or (max - extent).


Actually I like that idea. Refreshing only when a certain threshold is reached will be more efficient than what I'm currently doing. (It's a little like buffering .. just with columns instead of data bytes

Darryl Burke wrote:Make sure you setAutoResizeMode to AUTO_RESIZE_OFF. You're probably familiar with this, but I mention it because that's something I commonly forget about and have to go back and add after a trial run


Funny you mention it. I am familiar with it, but ... completely forgot about. Nice to know I'm not the only one
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:The requirement (and Paul's solution!) sounds just like the action of the vertical scrollbar on a Google Calendar widget (gadget?) as used in Google Sites. Maybe you could get some ideas from that.
Off the top of my head, I think I would add a AdjustmentListener to the horizontal scrollbar of the JTable's enclosing JScrollPane and initially add columns to the left or right when the scrollbar's value approached min or (max - extent).

I'm probably showing my ignorance about all things Spring and Swing, but it does seem to me that, in this age of database connectivity and webby stuff, a scrollable visual container based on some basic commands (row down/up, page down/up, newTopRow) wouldn't be a bad idea. I suspect it could even be implemented as an interface.

Is there such an animal already around?

Winston
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds too complicated for us simple souls on “beginning Java”; it might fit better in this forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic