Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable

 
keiyia jackson
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.
 
Swamy Vatti
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.
 
Javaoops
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic