By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

JTextField and Keymap

P: n/a
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.RI GHT);
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_EN D, 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());
.....
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.