• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Traversing GUI components

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone.
I am trying to setup my application so that the user can use it whether there is a mouse supplied or not so I need to be able to cycle through the screen components using the tab key for example.
My screen is divided into 3 JPanels using a BorderLayout - a search panel, booking panel and a status panel and my buttons and menu options have mnemonics set so they can be accessed no problem.
The problem is that I have 2 JComboBoxes in my search panel for the origin and destination values and I want to be able to cycle along both of these components as well as the search button with the tab key and then jump from the search panel into the booking panel and cycle through the JTable and onto book button then back to the beginning.
I can instantiate a DefaultFocusTraversalPolicy in the search panel and this works for that particular panel. It does seem to jump to the JTable somehow but then gets locked into it so that it cycles around and around the table's contents without ever stepping out and onto the book button let alone going back to the begining.
If I Instantiate the traversal policy in the root JFrame nothing happens at all.
Does anyone have any ideas about this as I don't really understand how the FocusTraversalPolicy classes are supposed to be used.
Many thanks
Sam
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It does seem to jump to the JTable somehow but then gets locked into it so that it cycles around and around the table's contents without ever stepping out and onto the book button let alone going back to the begining.


This is how it should be. To tab out of the table, hit Ctrl-Tab.
Eugene.
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A-ha!!! Thanks Eugene never thought to look at that.
Just had a closer look at the API for each component and sure enough there are listings of keypresses required for each one. You were right it was in fact working correctly bar the inclusion of the table's scrollpane and a textfield in the focus cycle which can be easily taken out.
The only thing I don't understand though is the placing of the call to setFocusTraversalPolicy.
If I place it in the main JFrame to pick up all components in the container it does nothing. So to get it working I have added it to my searchPanel which is one of three (search, booking and status) panels placed in the north, center and south areas of the JFrame respectively.
How on earth is the FocusTraversalPolicy picking up all the components in the searchPanel then stepping back and then forward again into the booking panel then out again and into the status panel?

Kindest regards Sam
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic