• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Focus Traversal Policy Question

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I've got a question on Focus Traversal. I understand that focus traversal allows the program to move the focus of the components around. I'm curious as to how/if I can make it move Up/down/left/right(4 different directions).

I will state more details on my program below.

Basically, I've designed a GUI program that detects keypress(UP,DOWN,LEFT,RIGHT,ESCAPE) only. Currently, I've completed the following:

Main frame(using JFrame)
-> with 8 buttons(using key binding to detect keypress)
-> each button upon pressing "ENTER" will open up a new JDialog(using focus traversal policy to move the focus around)(1x4 Layout)

Question: If I were to change my GUI interface(JDialog) to a 2x4 grid layout with 8 buttons. Is it possible for me to program my focus traversal to move left/right/Up/Down along the 8 buttons?



some codes that I've used to control up/down



Thanks in advance.

Best Regards
Adrian Lee
[ June 04, 2007: Message edited by: Adrian Lee ]
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can anyone enlighten me on how this can be done?
Many thanks.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks like you're possibly mis-interpreting FocusTraversalPolicy.

you can set the focus order of the next/previous components any way you want.
Using tab key (or shift/tab) will change focus to the next/previous component
(per the policy), but it is always the same order. you can change the forward/back
traversal keys as well.

what you've described as up/down/left/right is just a key binding, set to
change the focus to a particular component, relative to the current focused
component, not the next one in the FocusTraversalPolicy order.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:roll:

Thanks Michael.
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic