views:

276

answers:

5

Hey mates,

First of all I'm using netbeans as my IDE and I don't know if this is causing it. When I run my program (even if I have build it and run the .jar) I think it selects the tab that was previously selected (before quiting). So if for example I close the app with the third tab selected, it starts up with that selected again. Is there a known solution for this? The selectedIndex property on the jTabbedPane is set to 0. Shouldn't this property be the default onLoad value?

Thx in advance, Jimmy

PS. BTW for some reason it didn't submit my question in Opera (?)

A: 

The only way it can be set to an index other than zero is if the Java code contains:

tabbedPane.setSelectedIndex(...);

So search the source code for that line and fix it.

camickr
Already did mate. The only times I found it was when I called it, so nothing there.
Santeron
A: 

Besides using JTabbedPane.setSelectedIndex(), it's also possible to select a tab by calling JTabbedPane.setSelectedComponent(). Have you searched the code for setSelectedComponent() as well?

Joe Carnahan
yeah mate nothing there too...
Santeron
A: 

I have the same problem and neither of these solutions has helped. Using setSelectedComponent for an event listener does switch the tabs upon the event. However, using setSelectedComponent during the constructor of the View (form containing the tab pane) has no affect whatsoever -- this is where I see the selected tab set to the tab which was selected before I closed the previous app instance.

J.P.
A: 

Same problem here with Netbeans 6.8 and JTabbedPane. Neither setSelectedIndex() nor setSelectedComponent() makes a difference. The getSelectedIndex() returns the value previously set, but the pane is not selected correctly.

The reason for this is that the SingleFrameApplication saves it's state and restores the saved state on the next restart. This is done in the code generated by the GUI builder. You could see that startup() and configureWindow() methods of the SingleFrameApplication are overridden.

Workarounds:

  1. You could override the shutdown() method as well, then modifications to the configuration will not be saved. Note that the original will still be restored, so ensure that the required configuration is saved.

  2. Modifying the startup() method also helps:

MyView myView = new MyView(this);
myView.getFrame().setVisible(true);
myView.getFrame().pack();
chromecat
A: 

tabbedPaneName.setSelectedIndex(0);

just put that line in the place where the tabbed pane would be loaded if a button actuion will load the tabbed pane then put the line there but change tabbedPaneName to YOUR tabbed pane name.

mjoraid