• 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

JTable

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sometimes you feel like a nut. Sometimes you feel like a 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