File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Frustrating : JTable won't show.

 
achana chan
Ranch Hand
Posts: 277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
table.setVisible(true);

 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
achana chan
Ranch Hand
Posts: 277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic