JTextField and Keymap
From: Alexander Mazo (al_mazo_at_hotmail.com)
Date: 11/30/03
- Next message: Merlin_1102: "TextArea expands on own?"
- Previous message: Michael G: "Re: AWTEvents errors and deprecated methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Nov 2003 10:22:00 -0800
Hi!
I'm new in JAVA. I'm wont change "Home" and "End", but nothing
receive.
public class RLTextField {
public static String s = new String();
public static void main(String[] args) {
JFrame frame = new JFrame("RigthToLeftTextField");
final JTextField textField = new JTextField(30);
textField.setHorizontalAlignment(SwingConstants.RIGHT);
frame.getContentPane().add(textField);
class MyDocListener implements DocumentListener {
public void insertUpdate(DocumentEvent evt) {
Keymap km = textField.getKeymap();
KeyStroke ks_home = KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0);
KeyStroke ks_end = KeyStroke.getKeyStroke(KeyEvent.VK_END, 0);
Action act_home = km.getAction(KeyStroke.getKeyStroke
(KeyEvent.VK_HOME, 0));
Action act_end =
km.getAction(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0));
km.removeKeyStrokeBinding(ks_home);
km.removeKeyStrokeBinding(ks_end);
km.addActionForKeyStroke(ks_home, act_end);
km.addActionForKeyStroke(ks_end, act_home);
}
}
textField.getDocument().addDocumentListener(new MyDocListener());
....
- Next message: Merlin_1102: "TextArea expands on own?"
- Previous message: Michael G: "Re: AWTEvents errors and deprecated methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]