This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problems using JTabbedPane In a GUI application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems using JTabbedPane In a GUI application" Watch "Problems using JTabbedPane In a GUI application" New topic
Author

Problems using JTabbedPane In a GUI application

Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Hi

I making a GUI application, that uses JTabbedPane.
Each of the tab panes need to contain the same Jlabels.
I will add textboxes with specific information, once the Tab GUI's are completed.
I created button objects, they seem to appear correctly on the tab panes.
But the labels seem to not appear, on the other tab panes.

I am having problems in that the labels display on the last tab created, and not on the others.

I have included my code below.

Can anyone help ?


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Each component can only be added to one single parent component. So when you're calling that only works with one of the tab panels. All the others will not have the same panel. You'll need to create a new locinfoPanel with all of its contents for each tab you want to add it to.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Hi Rob.

I tried running my code with the modified for loop below, It had no effect to the GUI.
The panel with the locinfoPanel only displayed on the last tab panel.

In the loop I create a new locinfoPanel, and insert the labels each run through the loop.

Can you give me any suggestions..

Thanks

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You just shifted the problem.
Those 4 JLabels still can have only one parent, and that's the last created topPanel.
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Rob,
I understand what you are saying in regards to the labels having one parent.
And that parent would be displayed on the last tab created.

I am unsure as to how to be able to dynamically create multiple parents to be displayed on multiple tab panes.

I have tried to attach a index or counter to my parent topPanel, such as topPanel[index].
The IDE treated this as trying to create a array.

How can I solve my problem ??

Thanks

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Simply create the JLabels just like you create the panels inside the loop.
Rudy Rodriguez
Greenhorn

Joined: May 01, 2009
Posts: 29
Rob,
Thank You....
I followed your advice..

I got it working..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems using JTabbedPane In a GUI application
 
Similar Threads
Create panel depending on which tab is clicked in Swing
sharing Panel between frames
JTabbedPane with Keyevents
BorderLayout help
Using JTextFields in JTabbedPane