• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

adding a table to a frame

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a class A which extends JFrame. It creates an object of a class B which extends JTable. The constructor from class B creates a JTable object using the line:
JTable table = new JTable(tableModel);
When this object is added to the JFrame in class A, a blank rectangle appears. If I create the JTable using this line in the class B constructor:
super (new tableModel());
the table appears.
I would like to create the table using the first method. Would anyone know why the table doesn't appear?
I think I might be creating a JTable object but not returning it to the calling class A (because constructors don't return anything).
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May I make a remark ?
Extension is not the only way to use an object.
You say I extend the JFrame. Why ?
Does the new class is more specialized than the original ?
If it's the case, ok, let's extend it, but if not, avoid it.
Class A extends JFrame
{
JTable myTable; // to make it accessible in the class A
TableModel myTableModel; // idem
A()
{
super();
// you can use different layouts if you want.
// why not using JTable() instead of an extension of it.
myTable = new JTable();
myTableModel = new MyDataModel(); // extends the TableModel
myTable.setModel(myTableModel);
this.getContentPane().add(myTable);
}
}
------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic