This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

netbeans JTabbedPane setselectedindex  RSS feed

alex d´┐Żaz
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a swing form with a JTabbedPane on it. Whenever I open it, I want the first tab (tab 0) to be visible.

All is fine, this is working. However for the first time the dialog is opened. In this case the dialog opens at the tab pane it was closed on the previous time the application as a whole was executed. I have put default tabbedpane for open selectedindex 0, but it is not working, it is going to open the last tab pane opened.

I've tried several methods to make ensure the dialog is drawn after SelectedIndex has been set to 0 but all to no avail.

Do you know how I can setup tabbepane to start always in tab 0?

I will appreciate your help...

Maneesh Godbole
Posts: 11445
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "Dialog" I presume you mean JDialog/Dialog or essentially some modal window.

Looks like you are reusing the same JTabbedPane instance across JDialogs which would cause this behavior.

To fix it,, you can either:
1) Create a new JTabbedPane every time and then pass it on to the JDialog
2) Call JTabbedPane#setSelectedIndex(0)

If you are already going in for approach 2, perhaps you need to post that piece of code so others can take a look and try to figure out whats going wrong.
[ May 13, 2008: Message edited by: Maneesh Godbole ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!