This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problems with moving focus on buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems with moving focus on buttons" Watch "Problems with moving focus on buttons" New topic
Author

Problems with moving focus on buttons

Adrian Lee
Ranch Hand

Joined: May 10, 2007
Posts: 71
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: May 10, 2007
Posts: 71
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: May 10, 2007
Posts: 71
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: May 10, 2007
Posts: 71
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: May 10, 2007
Posts: 71
Thanks Michael
Adrian Lee
Ranch Hand

Joined: May 10, 2007
Posts: 71
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

Joined: Jun 09, 2003
Posts: 4632
> public class MyOwnFocusTraversalPolicy extends Entertainment

Entertainment is a JFrame.

try it as
public class MyOwnFocusTraversalPolicy extends FocusTraversalPolicy
Adrian Lee
Ranch Hand

Joined: May 10, 2007
Posts: 71
Thanks Michael.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with moving focus on buttons
 
Similar Threads
Frame with Keybinders and focus
invoke method with reflection
JScrollPane Frustrations
java applet redirect fails
invoke method with java reflection