Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JTable

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you place a new JTable on the frame if certain criteria is met outside of the frame's scope
example
class FirstFrame extends JFrame
{
....
public FirstFrame ()
{
......
}
private class MenuListener implements ActionListener
{
...
if(...)
{
...a new table= JTable (...)
....
TablescrollPane = new JScrollPane(a new table);
getContentPane().add(TablescrollPane);
....
}menuListener
}main
}frame class
basically, I need the tableinside of the if statement to replace the table on the main frame.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have a reference of the frame so that you can access it whereever you need.
I guess the frame is the main application frame. So it can be singleton. What I would do in this scenario is...
class MyFrame extends JFrame {
private static frame MyFrame;
private MyFrame () {
}
public static getFrame() {
if (frame == null)
frame = new MyFrame();
return frame;
}
And in the Listener(instead anywhere you want)...
I can use MyFrame.getFrame() to access the frame...
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite understand this. I simply need the table in a listener to replace the current table.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can replace the table with new table by creating a new instance for the table variable used earlier. Declare the table variable as global.
Moreover You can also change only the data or even struture of the exixting table. No need to create a new instance.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic