This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable" Watch "JTable" New topic
Author

JTable

keiyia jackson
Ranch Hand

Joined: Jul 16, 2001
Posts: 49
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

Joined: May 02, 2001
Posts: 57
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...


Swamy
keiyia jackson
Ranch Hand

Joined: Jul 16, 2001
Posts: 49
I don't quite understand this. I simply need the table in a listener to replace the current table.
Javaoops
Ranch Hand

Joined: Jun 21, 2001
Posts: 57
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.

 
GeeCON Prague 2014
 
subject: JTable