GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Initialize table with array of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Initialize table with array of objects" Watch "Initialize table with array of objects" New topic
Author

Initialize table with array of objects

Esteban Calle
Greenhorn

Joined: Aug 10, 2011
Posts: 6
Good mornigns
I have a problem to initialize the jtable from a FOR with BD or an array.

My problem is the example tableFilterDemo.java, I need the funcionality of this,
but when i want load data of my BD or an arraylist i have the problem.

I need load the array of objects with a FOR getting all the lines of file or rows of table

private Object[][] data = {
{ "Mary", "Campione", "Snowboarding"},
{ "John", "guifru", "skyiin"},};


Greetings
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2191
    
    7
Cross posted: http://stackoverflow.com/questions/7027947/initialize-table-with-array-of-objects/7028129#7028129

Be Forthright When Cross Posting To Other Sites
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Can you tell us what "FOR" and "BD" mean in your post?
Esteban Calle
Greenhorn

Joined: Aug 10, 2011
Posts: 6
Paul Clapham wrote:Can you tell us what "FOR" and "BD" mean in your post?



BD database and for is the cycle for
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

And what is a "cycle for"?

Edit: did you mean a "for loop"?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Okay, I think I might understand what your question is.

You aren't asking how to initialize a JTable from an array of arrays, you already know how to do that. You are asking how to produce an array of arrays from data which is in a database.

Am I right?
Esteban Calle
Greenhorn

Joined: Aug 10, 2011
Posts: 6
Paul Clapham wrote:Okay, I think I might understand what your question is.

You aren't asking how to initialize a JTable from an array of arrays, you already know how to do that. You are asking how to produce an array of arrays from data which is in a database.

Am I right?


at last someone understands me. YES it is my problem. loop for yes
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Okay. Your question is nothing to do with initializing the table from an array, it is all about creating that array. So using the title "Initialize table with array of objects" was very misleading and that is why nobody understands it.

Now I am going to make another guess. You cannot put the data from your database into an array, because you don't know how big the array should be. Is that right?
Esteban Calle
Greenhorn

Joined: Aug 10, 2011
Posts: 6
Paul Clapham wrote:Okay. Your question is nothing to do with initializing the table from an array, it is all about creating that array. So using the title "Initialize table with array of objects" was very misleading and that is why nobody understands it.

Now I am going to make another guess. You cannot put the data from your database into an array, because you don't know how big the array should be. Is that right?


yes it is correct, which would be the post title?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Then don't use an array of arrays. It's also possible to initialize a JTable with a Vector of Vectors.

Make a Vector for each row you get from the database, add each column to that Vector as an entry.

Then add each row Vector to a main Vector which represents the whole table.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

More cross posts
http://www.java-forums.org/awt-swing/47510-initialize-table-array-objects.html
http://www.dreamincode.net/forums/topic/243122-initialize-table-with-array-of-objects/


luck, db
There are no new questions, but there may be new answers.
Esteban Calle
Greenhorn

Joined: Aug 10, 2011
Posts: 6


Sorry. i won't do again
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2191
    
    7
at last someone understands me. YES it is my problem. loop for yes


Excuse me, you where given the answer to your question hours ago (in one of your many cross postings), if you would take the time to read your answers.

You don't understand how a TableModel works and the answer was to forget about Arrays because they are NOT dynamic.
 
GeeCON Prague 2014
 
subject: Initialize table with array of objects