aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to switch between tabs in swings? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to switch between tabs in swings?" Watch "How to switch between tabs in swings?" New topic
Author

How to switch between tabs in swings?

ragz wifer
Greenhorn

Joined: Dec 22, 2010
Posts: 22
Hi,

I have an swing application with a JTabbedPane containing some JPannels (tabs).I have a Button in tab1(say). I coded the Button action in such a way that it generates a new tab say tab2 which contains some components inside it but the thing is when a user clicks on tab2 user is able to see the components in Tab2

My Question is instead of user activity of clicking on tab2 is it possible to load and display tab2 components automatically and show it to user. What i mean to say is Bring it to front

any help is greatly aprized

Thanks in advance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Check out JTabbedPanel#setSelectedIndex()


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Click on the link that is automatically created for JTabbedPane. Scroll down to the method list. Read through them and see if one does what you want. I'll tell you two things:
1) there is at lease one such a method
2) it starts with set

Edit: Maneesh beat me to it. However, you can use the above steps to find a lot more useful methods, for all classes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ragz wifer
Greenhorn

Joined: Dec 22, 2010
Posts: 22
hi

i used the JTabbedPane.setSelectedIndex(-1); then it shows all the tabs where none of it got selected.

how to set index to a jpannel?how to bring tab2 to front???

here is my code what it does is its generating tab2 but my question is instead of user to click on tab2 tab2 should be loaded automatically when new client button is clicked

please and kindly help me
thanks in advance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

ragz wifer wrote:

i used the JTabbedPane.setSelectedIndex(-1);then it shows all the tabs where none of it got selected.


No surprises there.
From the API docs
The index must be a valid tab index or -1, which indicates that no tab should be selected


In the code you have posted, I do not see where you have used it
ragz wifer
Greenhorn

Joined: Dec 22, 2010
Posts: 22
Hi Maneesh

firstly i doesn't know how to set an index to a JPannel i.e.., a tab

once it is done that index value should be placed in the below line right?

JTabbedpane.setSelectedIndex();
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

In pseudo code

1) Create frame
2) Create tabbed pane
3) Add required tabs to tabbed pane
4) Add tabbed pane to frame
5) Select the required tab*

*Can be done on button click too
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to switch between tabs in swings?
 
Similar Threads
Reload tab with new page
how to reach current JTextArea
Need some suggestion preventing user mouse click
richfaces tabPanel problem
How to load tab content upon clicking the tab in JTabbedPane?