• Post Reply Bookmark Topic Watch Topic
  • New Topic

Focus Traversal Policy Question  RSS feed

 
Adrian Lee
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.
 
Michael Dunn
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!