This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes what will happen while adding already existing panel in JTabbedPane? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "what will happen while adding already existing panel in JTabbedPane?" Watch "what will happen while adding already existing panel in JTabbedPane?" New topic
Author

what will happen while adding already existing panel in JTabbedPane?

mohan rajv
Ranch Hand

Joined: Jan 28, 2009
Posts: 30
what will happen while adding already existing panel in JTabbedPane?

i have already added a panel Object in JTabbedPane.if i add the same panel again what will happen ?
and while adding panel i want to check whether a panel is exists in tat jtabbedpane or not..how to check tat..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

mohan rajv wrote:what will happen while adding already existing panel in JTabbedPane?
i have already added a panel Object in JTabbedPane.if i add the same panel again what will happen ?
and while adding panel i want to check whether a panel is exists in tat jtabbedpane or not..how to check tat..


How difficult is it to try out on your own and see? Takes less time than posting here doesn't it?
Check out JTabbedPane#getComponentAt(int index). If no panel exists you would get null.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
mohan rajv
Ranch Hand

Joined: Jan 28, 2009
Posts: 30
@Maneesh Godbole

i dont know the index of that panel.i have that panel object.and i have the jtabbedpane object.i want to check whether that panel is already there in my jtabbedpane or not..what should i do now?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

You do not need to know the index of the panel.
Just iterate through all the tabs (check out the API to figure out how to find out the tab count). Once you retrieve the Object at some specific index, check if it is the same panel you want and process accordingly.

Did you check out if you can add the panel twice? What result did you get?
mohan rajv
Ranch Hand

Joined: Jan 28, 2009
Posts: 30
if i add the same panel object again it is replacing the old one with that.i tried to add with new title it replaced the old one.

and i got a solution for my problem..instead of comparing the panel objects now i am comparing the panel titles.that s easy one..
 
jQuery in Action, 2nd edition
 
subject: what will happen while adding already existing panel in JTabbedPane?
 
Similar Threads
How to write a regex to include a text but exclude another text in the one regex?
refreshing the jtabbedpane
Multiple equal tabs in jTabbedPane
Setting background when extending JPanel
JTabbedPane Problem