Forums Register Login

Frame with Keybinders and focus

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Try a different condition:

Although this works okay on the contentPane you can get a more general affect if you register it on the JRootPane instead. See JRootPane api comments.
+Pie Number of slices to send: Send
Thanks a lot Craig. I will try that out.
+Pie Number of slices to send: Send
Hi everyone, I've got a question.

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.



Thanks in advance and taking time to reply me.

Adrian Lee
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Once again, thanks Craig!
+Pie Number of slices to send: Send
Hi again Craig. Sorry to trouble you.

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

Please advice on what I could do, Thanks Alot

Attached below is 2nd frame with buttons



Thanks again
Adrian Lee
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thanks for answering me, Craig.
Their achilles heel is the noogie! Give them noogies tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1345 times.
Similar Threads
invoke method with reflection
GUI help
invoke method with java reflection
Problems with moving focus on buttons
JScrollPane Frustrations
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:51:57.