Hi everyone. I'm trying to use keybinding for my frame. I'm starting with press down button. However, the focus doesn't go to the next button. Is my program wrong? Can anyone advice me on where I went wrong?
My program code is pasted below.
Thanks for your time.
Best Regards, Adrian Lee [ May 13, 2007: Message edited by: Adrian Lee ]
I have 2 Frames, a mainframe & a subframe. My mainframe window responds to a button and opens up a new frame(subframe) based on "arrow" keypress and "enter" key. I would like to have key bindings at the subframe window which have a different layout. Therefore, I've tried inserting key bindings in both class and running them. However, that doesn't seem to work. Is there something that I need to change?
The codes that I've used in my mainframe to open a new class(subframe) is shown below.
Use the down key to navigate to the Entertainment button and press the space bar. Use the up key to change the color in the dialog. In general we try to have only one JFrame at a time and use dialogs for secondary top–level containers. There are three conditions that you can try to find what works for the InputMaps. These are found in the JComponent api Method Detail for the getInputMap(int condition) method.
I've been testing out the new frame and trying a few ways to go around it.
It seems that I can only use WHEN_IN_FOCUSED_WINDOW instead of WHEN_ANCESTOR_OF_FOCUSED_COMPONENT for the new frame with buttons. From there onwards, the frame goes back to the 1st problem that I've encountered earlier on. (When I press Up, Focus will get stuck on the next button and program will halt.) Is there another way to solve this?
Another question that I would like to ask is : Is it possible to open a few dialog boxes? As in JDialog1 -> JDialog2 -> JDialog3
It looks like you are designing a keyboard navigation system for your app. The key binding approach, which may be workable, seems unwieldy for this. I would consider using the default Swing setup which is keyboard navigation with the tab key in combination with a FocusTraversalPolicy. This is discussed with examples in How to Use the Focus Subsystem. See sections "Customizing Focus Traversal" and "Tracking Focus Changes to Multiple Components". The intro shows how to set up custom focus traversal keys if the tab key is unsuitable. Is it possible to open a few dialog boxes? As in JDialog1 -> JDialog2 -> JDialog3 Yes. Make sure they are non–modal or they will freeze everything up.