Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

how to interrupt a tab selection?

Thread view: 
Joe - 23 Feb 2008 18:27 GMT
I have several tabbed panes in a JPanel and I would like to be able to
catch a tab click before the selected tab is actually displayed. A
small dialog will popup, the user makes a selection, then the dialog
goes away and the selected tab will be displayed.

Anyone know how to do something like this? I have a ChangeListener on
my JTabbedPane but, what I think I need is something like a
willDisplayTab() method of sorts.
Alexander.V.Kasatkin@gmail.com - 23 Feb 2008 21:12 GMT
> what I think I need is something like a willDisplayTab() method of sorts.

To switch pages, the JTabbedPane use the SingleSelectionModel instance
(model field).
You can enhance the DefaultSingleSelectionModel class (I mean the
setSelectedIndex() method)
and set set it to tabbed pane using the JTabbedPane.setModel() method.
Joe - 23 Feb 2008 21:28 GMT
> To switch pages, the JTabbedPane use the SingleSelectionModel instance
> (model field).
> You can enhance the DefaultSingleSelectionModel class (I mean the
> setSelectedIndex() method)
> and set set it to tabbed pane using the JTabbedPane.setModel() method.

Thanks, but I don't want to change the model. I just want to catch the
changeevent, show a dialog, then let the changeevent continue to
actually displaying the tab the user clicked on.
Alexander.V.Kasatkin@gmail.com - 23 Feb 2008 21:51 GMT
> > To switch pages, the JTabbedPane use the SingleSelectionModel instance
> > (model field).
[quoted text clipped - 5 lines]
> changeevent, show a dialog, then let the changeevent continue to
> actually displaying the tab the user clicked on.

the event originally is sent by model, handled by tabbed pane UI and
after that transferred to you.
So you can include your additional code into the model before it fires
a change event:

// DefaultSingleSelectionModel.java
public void setSelectedIndex(int index) {
 // show a dialog here
 // or create and fire your own additional event
 // or do something else you want
 // or return without switching pages
 if (this.index != index) {
   this.index = index;
   fireStateChanged();
 }
}
Joe - 24 Feb 2008 06:07 GMT
> the event originally is sent by model, handled by tabbed pane UI and
> after that transferred to you.
> So you can include your additional code into the model before it fires
> a change event:

This is working for me, but the only problem I'm having is that I can't
figure out how to get the source of the event before the
setSelectedIndex() method is called. I see it afterwards.

I've implemented ChangeListener on my class extended from
DefaultSingleSelectionModel, but the stateChanged() doesn't get called.

What am I doing wrong there?
Alexander.V.Kasatkin@gmail.com - 24 Feb 2008 12:58 GMT
> > the event originally is sent by model, handled by tabbed pane UI and
> > after that transferred to you.
[quoted text clipped - 9 lines]
>
> What am I doing wrong there?

It too hard for me to understand it without code you wrote,
so I've updoaded my simple example on the Google code:

http://code.google.com/p/javacodesnippets/downloads/list

Try to download these files.

BR, Alex


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.