Java Swing - O Reilly Removes (Free web hosting with ftp) a listener from
Java Swing - O Reilly Removes a listener from the list of listeners. It is synchronized, in an effort to make this class as thread-safe as possible. 27.3.2 The KeyStroke Class Another convenient class for dealing with events is the KeyStroke class. This class allows you to associate actions with particular events through the KeyMap class. Figure 27.5 shows an example of a JTextArea with support for the “CTRL-A” select-all action, using a KeyStroke. Figure 27.5. A text area with support for a “Select All” keyboard shortcut Here’s the code that created the selectable text area. With the help of the AbstractAction class and the selectAll() method in JTextComponent, the code is very simple. We get the KeyMap for the text area and add in an association between the CTRL-A keystroke and the selectAll() method using the addActionForKeyStroke() method. The getKeyStroke() call gives us the correct keystroke, and the call to the selectAll() is encapsulated in the Action object. It doesn’t take much code: // SelectableTextArea // A class that extends JTextArea and supports the common Ctrl-A shortcut // for selecting all of the text in the field. // import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class SelectableTextArea extends JTextArea { public SelectableTextArea(String text, int rows, int cols) { super(text, rows, cols); Keymap km = getKeymap(); // get the “Ctrl-A” key code // and attach it to a selectAll() call for this component km.addActionForKeyStroke( KeyStroke.getKeyStroke(’A', KeyEvent.CTRL_MASK, true), new AbstractAction() { public void actionPerformed(ActionEvent ae) { SelectableTextArea.this.selectAll(); } } ); } } And the application that puts this text area to use is also straightforward: - 931
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.