File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Frustrating : JTable won't show. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Frustrating : JTable won Watch "Frustrating : JTable won New topic

Frustrating : JTable won't show.

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi, I modified my working code to put the table definition in a "sub-class" TableDefinition(), but the table is not displayed anymore that that although it compiles error-free.
It's been pretty frustrating the whole day. Any pointers and hints will be much appreciated:

humanum errare est.
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

One problem is that the object you are adding to the GUI is an extension of JTable called TableDefinition:
Originally posted by achana chan:

newtableDef = new TableDefinition();
scrollPane = new JScrollPane(newtableDef);

But you are setting the data on an instance variable of SimpleTableDemo called table. table never gets added to the GUI, so the data never gets displayed.

table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(4, 10));

[How To Ask Questions On JavaRanch]
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

The "TableDefinition" class shouldn't extend JTable... all it's doing is providing data to the "table" variable in your outer class. You are adding the empty "TableDefinition" table (provided only because it extends JTable...) to your scroll pane when you should be adding the "table" table instead.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi all.
I've finally got it working the way I want it to, by extending AbstractTableModel instead of JTable in my inner class.
Thanks for taking time to help me out, much appreciated.
I agree. Here's the link:
subject: Frustrating : JTable won't show.
It's not a secret anymore!