Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

JTable to show several sets of data

Thread view: 
Dag Sunde - 07 Jan 2005 06:50 GMT
I posted this in c.l.j.p. earlier this week, but
no response. So I try here instead, even tho the
question is more about choice of data strukture
than gui...

I have a scenario where I'm struggling a little bit
on what is the best approach:

My base set of data to show is a Bid
  - Coloumn headers are the prices,
  - 24 rows one for each hour in the day
  - the data is volumes for each price/hour
  - The user can add new columns
  - A bid always have two columns (minprice & maxPrice)
    that can't be changed by the user

The user can add new bids (I maintain a collection of Bid)

The Gui represent different Bids as Tabs the user can click
on to select a particular bid to vork with.

Now to my question:

Do I put a datamodel into each bid, and use
table.setModel(bid.model), or do I use a single datamodel
and write code in that model to retrive data from the "current"
bid, and call .fireTableStructureChanged() to inform the table
that it have to redraw itself from scratch?

Or does anyone have a completely different idea?

TIA...

Signature

Dag.

ian.a.desouza@gmail.com - 07 Jan 2005 22:42 GMT
A table should represent a collection of something. If you want a bid
table, create a TableModel that contains a set of bids and override the
required methods of TableModel.

If you want 24 rows and 2 columns (min/max) then return 2 for column
count, and 24 for row count, and create the appropriate algorithm to
determine the getValueAt for each of the 24*2 cells.
Dag Sunde - 08 Jan 2005 00:22 GMT
> A table should represent a collection of something. If you want a bid
> table, create a TableModel that contains a set of bids and override the
[quoted text clipped - 3 lines]
> count, and 24 for row count, and create the appropriate algorithm to
> determine the getValueAt for each of the 24*2 cells.

I'm perfectly aware of that.

What I was asking, is:

From a design perspective, when a table is going to
show multiple datasets, is it best to:

* Have one single tablemodel for the table, and change the underlying
 dataset for the Model?

or...

* Have one tablemodel for each dataset, and change the model for
 the table?

Signature

Dag.

Bryan Cooper - 09 Jan 2005 18:10 GMT
>> A table should represent a collection of something. If you want a bid
>> table, create a TableModel that contains a set of bids and override the
[quoted text clipped - 18 lines]
> * Have one tablemodel for each dataset, and change the model for
>  the table?

>Do I put a datamodel into each bid, and use
>table.setModel(bid.model), or do I use a single datamodel
>and write code in that model to retrive data from the "current"
>bid, and call .fireTableStructureChanged() to inform the table
>that it have to redraw itself from scratch?

It sounds like your original idea would be more appealing to me (above).
Create a TableModel to handle the data for each bid (which is made up of
2x24 dataset) and the data events for each bid (E.G. handling
fireTableStructureChange events when users add columns, etc).  Create
separate instances of the TableModel for each bid.  You only need to
maintain one class to deal with bid data.

If the generic JTable suits your needs, just use it on each tab or customize
one to handle your requirements (maybe the headers need to be fancy or the
cells need some color coded rendering).  Again, only need to maintain one
class for a customized view and in each tab you can have an instance.

Hope this helps a little...
Best Regards,
Bryan Cooper


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.