• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with moving focus on buttons

 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone, sorry for the trouble caused. I need help on solving this problem. The buttons' focus can't seem to move to the next button.

Porgram scope:
Main frame (entertainment frame)
sub frame (movie frame)

Main frame and sub frame has a few buttons. This program only functions with (Up,Down,Left,Right and Escape). Main Frame has accomplised the shifting focus to next button.

However, sub frame is having problems to shift the focus. I've tried a few methods to overcome(keybinding,focus transversal,window listener..). Still no results in solving this.

**I'm currently using down arrow for moving of focus to next button in sub frame.



Thanks in advance for the help.

-------------
Adrian Lee
[ May 20, 2007: Message edited by: Adrian Lee ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems to work OK for me.
describe the steps to take to produce the unwanted behavior


> This program only functions with (Up,Down,Left,Right and Escape).
tab key also works
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael, I'm trying to navigate throught the sub frame with key press Up, Down, Left, Right(currently testing out with down press). I do not wish to use other key press. Thanks for taking time to read through and helping.

Adrian Lee
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still can't see any problem behavior.

I run the program, there are 5 buttons under 'video' another 2 under 'audio',
all keys work OK up/down/left/right. The only difference in using those keys
is the left/right don't wrap like up/down does. Is this the problem?
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael. There isn't any problem with the main frame. The problem I'm currently facing is on the sub frame. Which will be opened when I pressed enter on the movie button. I can't seem to transfer the focus to another button like the main frame does(*using Up,down,left,right keypress). I've tried using keybinding,focus transversal,window listener. Thanks

Adrian Lee
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the dialog is a separate entity, so you'd have to set up the traversal
the same way you've done with the main frame
e.g. the down arrow key - I've just copied your main frame code and added it
to the dialog. Now, when the dialog shows, the down key works
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael. Thanks for pointing out.

By the way, Is there any other ways that I can control the focus to move within the few buttons itself? Because It seems that the focus on my sub frame seems to move out.

Adrian Lee
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Is there any other ways that I can control the focus to move within the few buttons itself?

set your own FocusTraversalPolicy

http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#customFocusTraversal
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael. I added the following custom Focus Traversal Policy to it.
However, I got the message that says :
The method (setFocusTraversalPolicy) in the type Container is not for the arguments (Entertainment.MyOwnFocusTraversalPolicy).




[ May 23, 2007: Message edited by: Adrian Lee ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> public class MyOwnFocusTraversalPolicy extends Entertainment

Entertainment is a JFrame.

try it as
public class MyOwnFocusTraversalPolicy extends FocusTraversalPolicy
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic