JTabbedPane showing both tabs on a launch


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JTabbedPane showing both tabs on a launch

Hybrid View

  1. #1
    Sharon Guest

    JTabbedPane showing both tabs on a launch


    Hello. I have an application running on JTabbedPane which consists of two
    JPanels. When the application is first launched, it shows components on
    both tabs until I click on one of the tabs, which then displays only the
    components on the tab.

    Each tab consists of it's own GridBagLayout and components are added to it.

    The code is quite long but just to give you the idea,

    public void init()
    {
    resize(660, 600);
    setBackground(Color.lightGray);
    setLayout(new GridLayout());

    JTabbedPane mTabbedPane = new JTabbedPane();
    mTabbedPane.addTab("Recording Mode",recordPanel());
    mTabbedPane.addTab("Playing Mode",playPanel());
    mTabbedPane.setSelectedIndex(0);
    add(mTabbedPane);
    addMouseListener(this);
    }

    public JPanel recordPanel()
    {
    JPanel recPanel = new JPanel(false);
    GridBagLayout recGridBag = new GridBagLayout();
    GridBagConstraints recConstraints = new GridBagConstraints();
    recPanel.setLayout(recGridBag);
    Insets mInsets = new Insets(10,30,10,30);
    *---------components added to the recGridBag---omitted------*

    public JPanel playPanel()
    {
    JPanel playPanel = new JPanel(false);
    GridBagLayout playGridBag = new GridBagLayout();
    GridBagConstraints playConstraints = new GridBagConstraints();
    playPanel.setLayout(playGridBag);

    *---------components added to the playGridBag---omitted------*

    Thank you.




  2. #2
    Essey Guest

    Re: JTabbedPane showing both tabs on a launch


    "Sharon" <som@softtracks.com> wrote:
    >
    >Hello. I have an application running on JTabbedPane which consists of two
    >JPanels. When the application is first launched, it shows components on
    >both tabs until I click on one of the tabs, which then displays only the
    >components on the tab.
    >
    >Each tab consists of it's own GridBagLayout and components are added to

    it.
    >
    >The code is quite long but just to give you the idea,
    >
    >public void init()
    >{
    > resize(660, 600);
    > setBackground(Color.lightGray);
    > setLayout(new GridLayout());
    >
    > JTabbedPane mTabbedPane = new JTabbedPane();
    > mTabbedPane.addTab("Recording Mode",recordPanel());
    > mTabbedPane.addTab("Playing Mode",playPanel());
    > mTabbedPane.setSelectedIndex(0);
    > add(mTabbedPane);
    > addMouseListener(this);
    >}
    >
    >public JPanel recordPanel()
    >{
    > JPanel recPanel = new JPanel(false);
    > GridBagLayout recGridBag = new GridBagLayout();
    > GridBagConstraints recConstraints = new GridBagConstraints();
    > recPanel.setLayout(recGridBag);
    > Insets mInsets = new Insets(10,30,10,30);
    >*---------components added to the recGridBag---omitted------*
    >
    >public JPanel playPanel()
    >{
    > JPanel playPanel = new JPanel(false);
    > GridBagLayout playGridBag = new GridBagLayout();
    > GridBagConstraints playConstraints = new GridBagConstraints();
    > playPanel.setLayout(playGridBag);
    >
    >*---------components added to the playGridBag---omitted------*
    >
    >Thank you.
    >
    >
    >


    Programmatically select a tab that you want.

    To do this in your code you could insert the following line at the end of
    your init() function:

    mTabbedPane.setSelectedIndex(0); // programatially sets the intital tab
    to the first tab


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center