Solved

JTable with Arrays

Posted on 2004-10-18
9
378 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
runtime exception 2 42
How do I remove an object from a 3 40
ejb entity bean example issue 2 17
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

830 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