This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one 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


Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable