Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Frustrating : JTable won't show.

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic