aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Tab Change Issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Tab Change Issues" Watch "Tab Change Issues" New topic
Author

Tab Change Issues

Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
I have a GUI with 3 tabs in JFrame in which I'm doing a small search task for a file.
If file not found then throw exception & show a certain tab on the frame.

So how can I change the view from the first tab to the a different tab on actionevent ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Well, assuming that the component you were thinking of was a JTabbedPane, you would do what the tutorial suggests:
How to Use Tabbed Panes wrote:To switch to a specific tab programmatically, use the setSelectedIndex or the setSelectedComponent methods.
Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
Paul Clapham wrote:Well, assuming that the component you were thinking of was a JTabbedPane, you would do what the tutorial suggests:
How to Use Tabbed Panes wrote:To switch to a specific tab programmatically, use the setSelectedIndex or the setSelectedComponent methods.


Couldn't get that to work, could you give me an example ?

Here's my code :

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Oh, it's that question again. ("How do I access a member of Class A from code in Class B?") You'll need to have a reference to the object you want to work with. Creating another copy of that object and working with it won't have any effect on the copy you should have been working with. So basically you're going to want

where "Tabs" is a reference to the object created in the first line of your posted code.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
First of all learn to use proper Java variable conventions. Variable names DO NOT start with an upper case character.

"Tabs" should be "tabs".
"Mframe" should be "mFrame".

If you want to change the selection of a tab then just select the tab. There is no need to create a new tabbed pane. Just do:

 
 
subject: Tab Change Issues