• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Create panel depending on which tab is clicked in Swing

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on which tab is clicked in the JTabbedPane, a corresponding panel will be created.
I have created a simple test program as follows.


Currently all the source code are in the same file.
I like to extract all the panel codes and put them in their own files like the following files.
How to do that?
Is this the correct approach or something should be done in ChangeListener?
Panel1.java



JTabbedPane_Panel.java


 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you move the code that creates your panels from one file to their own, that suggests you will be creating new classes for each panel. So, to add those panels to your JTabbedPane, you would do something like:

tabbedPane.addTab("Tab 1", icon, new PanelOnePane( possible arguments ),
"Does nothing");

where PanelOnePane( possible arguments ) is a panel building class that you separated from your current single file that would extend JPanel.

Of course, you could instantiate the PanelOnePane before adding it to your tabbedPane with

PanelOnePane panelOnePane = new PanelOnePane( possible arguments );

Make sense?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic