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 / GUI / March 2005

Tip: Looking for answers? Try searching our database.

Using function keys to select a certain tab in a JTabbed pane

Thread view: 
Charley Liu - 10 Mar 2005 15:03 GMT
I want to use the function keys (F1,F2,F3 etc.) to select certain tabs
within my JTabbed pane. I know how to use keylistener and can use it to
detect the actual keys being pressed but i can't figure out how to change
the tabs according to the button pressed.

Can someone help me?
John McGrath - 14 Mar 2005 03:44 GMT
> I know how to use keylistener and can use it to detect the actual keys
> being pressed but i can't figure out how to change the tabs according to
> the button pressed.

You first mention keys, then you mention "button".  Are you using "button"
as a synonym for "key", or are you asking about also using something like
a JButton to switch the tab?

Signature

Regards,

John McGrath

Charley Liu - 14 Mar 2005 17:31 GMT
I was referring to the function keys such as F1, F2, F3 etc. I would also
like to use JButtons external to the JTabbed pane to switch between tabs
too. Any ideas?
John McGrath - 15 Mar 2005 00:29 GMT
> I was referring to the function keys such as F1, F2, F3 etc. I would also
> like to use JButtons external to the JTabbed pane to switch between tabs
> too. Any ideas?

For the function keys, you will need to map the Keystroke to the tab that
you want to select.  For this, I would use a java.util.Map.

For buttons, I would use a "client property" on the button that would
indicate what tab to switch to.  Then you could use a single Action for
all of the buttons.  It would get the client property from the source of
the event and use that to switch the tabs.

Signature

Regards,

John McGrath

ninhoa@yahoo.es - 16 Mar 2005 15:17 GMT
Add a KeyListener to your JTabbedPane and then (for example with 2 tabs):

       if (e.getKeyCode()==KeyEvent.VK_F1)
           getJTabbedPane().setSelectedIndex(0);
       else if (e.getKeyCode()==KeyEvent.VK_F2)
           getJTabbedPane().setSelectedIndex(1);

or setSelectedComponent(Component c)
Charley Liu - 20 Mar 2005 13:25 GMT
Thanks, that was exactly what I needed to know =)


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.