marttriada.blogg.se

Bluej program menu shortcut
Bluej program menu shortcut











This input map is commonly used for mnemonics or accelerators, which need to be active regardless of where focus is in the window. JComponent.WHEN_IN_FOCUSED_WINDOW The component's window either has the focus or contains the component that has the focus. For example, JTables make all their bindings using WHEN_ANCESTOR_OF_FOCUSED_COMPONENT so that if the user is editing, the up-arrow key (for example) still changes the selected cell. This input map is commonly used for a composite component — a component whose implementation depends on child components. JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT The component contains (or is) the component that has the focus. These bindings are only effective when the component has focus. For example, buttons bind the Space key using the WHEN_FOCUSED map. The WHEN_FOCUSED input map is typically used when the component has no children. The input maps correspond to the following focus situations: JComponent.WHEN_FOCUSED The component has the keyboard focus. In this way, any bindings specified by the developer are never lost on look and feel changes.Įach JComponent has one action map and three input maps. Any time the look and feel is changed, the parent is reset. By convention, however, you use a string that names an action.Įach InputMap/ ActionMap has a parent that typically comes from the UI. Technically, you don't need to use action names in the maps you can use any object as the "key" into the maps. An input map binds key strokes to action names, and an action map specifies theĪction corresponding to each action name. The key binding support provided by JComponent relies on theĪctionMap classes.

bluej program menu shortcut

The rest of this section gives you the details you need to use key bindings: Another advantage of Actions is that they have an enabled state which provides an easy way to disable the action without having to track which component it is attached to. Also, they make it easy to change the key to which an action is bound.

#Bluej program menu shortcut code

Some of the advantages of key bindings are they're somewhat self documenting, take the containment hierarchy into account, encourage reusable chunks of code ( Action objects), and allow actions to be easily removed, customized, or shared. Key listeners are also difficult if the key binding is to be active when the component doesn't have focus. Key listeners have their place as a low-level interface to keyboard input, but for responding to individual keys key bindings are more appropriate and tend to result in more easily maintained code. You can find coverage of mnemonics and accelerators in the section JLabel) and accelerators (supported by menu items).

bluej program menu shortcut

They're used behind the scenes by mnemonics (supported by all buttons and by tabbed panes as well as by

bluej program menu shortcut

You often don't need to use key bindings directly. You want to provide a new key binding for an existing action.įor example, you might feel strongly that Control-Shift-Insert should perform a paste operation.You want to override the behavior of an existing key binding.įor example, if your application normally reacts to presses of the F2 key in a particular way, you might want it to perform a different action or ignore the key press.You're creating a custom component and want to support keyboard access to it.įor example, you might want the component to react when it has the focus and the user presses the Space key.Here are some examples of when key bindings are appropriate: The JComponent class supports key bindings as a way of responding to individual keys typed by a user.











Bluej program menu shortcut