aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Which data structure I have to use for table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Which data structure I have to use for table?" Watch "Which data structure I have to use for table?" New topic
Author

Which data structure I have to use for table?

Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Hello all,
I need to use a table like this:

http://www.optizone.it/tgu.html


What kind of data structure is the best?
I doesn't need to be updated, I only need to read it!

Thanks!


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
List of Lists of Integers?
Array of arrays of ints?
You would have to pad those structures with 0s, and display the 0s as blanks, at least on their “left” side.

Can you change the entire table into a formula?
Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Campbell Ritchie wrote:
Can you change the entire table into a formula?


No, I can't! They are precalculated values!
I was thinking about a DB, but not sure about it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Don’t like that website. It told me that 100g pane di grano duro (bread from strong flour) contains 0 proteine and 6.6 carboidrati, which I am sure is incorrect.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Alessandro Camel wrote:
I was thinking about a DB, but not sure about it.

Are you asking about how your data should physically be stored on your hard drive or about how the data can be displayed in Java?


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Riaan Nel wrote:
Alessandro Camel wrote:
Campbell Ritchie wrote:
I was thinking about a DB, but not sure about it.

Are you asking about how your data should physically be stored on your hard drive or about how the data can be displayed in Java?


To be honest... both! ;)
This is the first time I come across a structure like this and I am not sure how I should store and access it.
No need to be to display it! I only need to read it.
Also, keep in mind that I only need to access it once: so, maybe, loading in memory could be a waste of memory space.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Alessandro Camel wrote:
To be honest... both! ;)
This is the first time I come across a structure like this and I am not sure how I should store and access it.
No need to be to display it! I only need to read it.
Also, keep in mind that I only need to access it once: so, maybe, loading in memory could be a waste of memory space.

You can store it in a database, but you'll still need to put it in a format that Java can understand. I'd go for a JTable and a DefaultTableModel (since the data is not editable, use the constructor that takes a 2D* object array). This is assuming that you'll be displaying your data in a Swing app.

For the data to be displayed, it has to be in memory, so there's no way that you can get around that. After all, you can't display something that isn't there.

Edit: * Java doesn't have actual 2D arrays, it has arrays of arrays.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
What’s a 2D array? Do you mean an array of arrays?

At this stage, I think this discussion might fit better in our GUIs forum, so I shall move it.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Campbell Ritchie wrote:What’s a 2D array? Do you mean an array of arrays?

Noted, and fixed.
Cole Terry
Ranch Hand

Joined: Nov 23, 2011
Posts: 45
Wow! It's an awesome structure I have ever seen. I think it's quite different to implement such table structure with regular JTable.
I have one idea: create that table in HTML put the HTML code into a JTextPane. How does that sound?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Terrible. When you need to get the value of a specific cell you need to parse the entire HTML document.

Since the matrix is somewhat sparse, perhaps a Map<Point,Integer> is an option. The Point will contain the height and weight, but you must make sure that these Point objects never get modified, or they will no longer work correctly as Map keys. Alternatively you can create your own immutable class that represents the height and weight, and use instances of that as keys.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which data structure I have to use for table?