Frontpage web hosting - Java Swing O Reilly You can associate keyboard

Java Swing O Reilly You can associate keyboard actions to a component through one of two registerKeyboardAction() methods: void registerKeyboardAction(ActionListener anAction, String aCommand, KeyStroke aKeyStroke, int aCondition) void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition) In order to use these methods, you need a couple of things: a KeyStroke object that represents the keystroke combination you wish to monitor, and an Action that occurs when that keystroke has taken place. (Actions are covered earlier in the chapter.) If you want the keyboard event to insert a specific string as the event’s action command, you can specify that as well. A final parameter to the registerKeyboardAction() method places restrictions on when the action is fired. Table 3.7 shows the constants for the final parameter. Table 3.7, Constants for Keystroke Registration Constant Description WHEN_FOCUSED The Action takes place only when the target component has the focus. The Action takes place when the target component has the focus or WHEN_IN_FOCUSED_WINDOW resides in a container that has the focus. The Action takes place when the target component has the focus, or is WHEN_ANCESTOR_OF_FOCUSED_WINDOW the ancestor of the component that currently has the focus. The latter two constants come in handy in different situations. JComponent.WHEN_IN_FOCUSED_WINDOW can be used in a situation where you want to define a keystroke that works on a specific component in a container, but functions even when the parent container has the focus. For example, a dialog could have a save button that captures the letter “S” in conjunction with a modifier key (ALT, CTRL, or SHIFT). It could register this keyboard action with the button to perform a save when the “S” key was pressed. The keyboard action would work even if the button didn’t explicitly have the focus as long as the parent dialog did. On the other hand, if you want to define a keyboard event that is standardized throughout a container and its components, register a keyboard event at the container level and use the JComponent.WHEN_ANCESTOR_OF_FOCUSED_WINDOW option. This allows keyboard events to be recognized at the container level, even if the descendant has the focus. You can use the registeredKeyStrokes property of JComponent to get access to all the keystrokes registered for a component. The getRegisteredKeyStrokes() method returns this information as an array of KeyStroke objects. If you want to see what condition is tied to any particular keystroke, you can use the getConditionForKeyStroke() method. If you want to obtain the action associated with the keystroke, use getActionForKeyStroke() . In both cases, you will have to specify the target keystroke as the search key. 3.3.2.13 Accessibility As we mentioned in Chapter 1, one entirely new feature about Swing components is that they support accessibility options. Accessibility options are constructed for users who have trouble with traditional user interfaces, and include support for alternative input and output devices and actions. There are several parts to accessibility; they are covered in more detail in Chapter 25, and Chapter 26. JComponent implements the methods required by the Accessible interface, though it does not implement the interface itself. - 67 -
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

Leave a Reply