• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to switch between tabs in swings?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out JTabbedPanel#setSelectedIndex()
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ragz wifer
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic