Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable test not working...

Status
Not open for further replies.

asiavoices

Programmer
Sep 20, 2001
90
CA


Hello everyone,

I was wondering why I'm getting this error when I try to set up my JTable? I'm just creating one to learn more about it.

Here's my code.......

/* ===================================
* Rong.java =
* =================================== */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import javax.swing.table.*;

public class Rong extends JFrame

{

............


public static void main(String[] args)
{

Rong myLayout = new Rong();

myLayout.setVisible(true);

} // End of void main() method


/* -------- constructor --------- */

public Rong()
{

final String[] colHeads = { "itemName", "itemPrice", "itemTax" };

Date currentDate = new Date();
Container contentpane = getContentPane();
contentpane.setLayout(new BorderLayout());

setSize(620,415);
setTitle("Rong" + currentDate.toString());
setBackground(new Color(204,255,204));


/* ---- Populate ArrayList (ie. MyStuff) ---*/

ArrayList myStuff = new ArrayList();

for (int idx=0; idx < 20; idx++)
{
Item cidx = new Item(Integer.toString(idx), 99.0d, false);
myStuff.add(cidx);
setTotal(getTotal() + 99.0d);
numrecords++;
}

Object ia[] = myStuff.toArray();

error here ---> JTable mytable = new JTable(ia, colHeads);


} // end of Rong constructor


} // end of Rong class



Here's the error message: ==================

Rong.java [94:1] cannot resolve symbol
symbol : constructor JTable (java.lang.Object[],java.lang.String[])
location: class javax.swing.JTable

JTable mytable = new JTable(ia, colHeads);
^
1 error
Errors compiling Rong.

This is straight forward isn't it?

Thanks,

Christopher


 
JTable takes a two-dimensional array of data, and a one-dimensional array of column names.

your ia is only a one-dimensional array.
 
Hello again cyli & everyone,

If this is the case, how could I load in my ArrayList (3 fields.) then into a JTable and then display them onto a panel?

...
Item cidx = new Item(Integer.toString(idx), 99.0d, false);
.....

Item is my class that contains 3 fields/variables.


thanks again,

Christopher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top