Solved

JTable with Arrays

Posted on 2004-10-18
9
375 Views
Last Modified: 2010-03-31
I am after Jtable code that will display the rows and columns of a 2d array called returned array. Can anyone help? I am currently using a for loop within main to populate a variable with the values from the array, which is then displayed via a dialog box.

Cheers

0
Comment
Question by:Cyart
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 12336912
Vector data = new Vector();
Vector cols = new Vector();
// add columns names

for (int i=0; i<array.length; i++)
{
   Vector row = new Vector();
   for (int j=0; j<array[i].length; j++)
   {
      row.add(new Integer(array[i][j]);
   }
   data.add(row);
}
JTable table = new JTable(data, cols);
0
 

Author Comment

by:Cyart
ID: 12336937
can you explain what a vector is cheers?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12336977
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 92

Expert Comment

by:objects
ID: 12336986
A Vector class is a (growable) array of objects.
0
 

Author Comment

by:Cyart
ID: 12337028
Ok how do I display the table
0
 
LVL 92

Expert Comment

by:objects
ID: 12337045
add it to your component hierarchy.
eg. to add it to your dialog you could use:

dialog.getContentPane().add(table);
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 12337062
use JScrollPane and add ur JTable to it

    jspTableScroller.getViewport().add(jtData, null);


Naeem Shehzad Ghuman
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12337203
I will post a code soon.
0
 
LVL 1

Expert Comment

by:scanadmin
ID: 12349661
create a model class extending AbstractTableModel,

place your vectors in there and fill in the code for the getElementAt(int row, int col)

then make your jtable and pass it the new class as its model,

when you call fireStateDataChanged(); in the model this will fill the data for you.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question