• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Frame with Keybinders and focus

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Craig. I will try that out.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once again, thanks Craig!
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for answering me, Craig.
 
reply
    Bookmark Topic Watch Topic
  • New Topic