Monday, December 27, 2010

To avoid JTextField copy in Java

// To avoid TextField copy
public void avoidTxtFieldCopy(JTextField mytextfield)
{
JTextComponent.KeyBinding[] newBindings = {
new JTextComponent.KeyBinding(
KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK),
DefaultEditorKit.beepAction),
new JTextComponent.KeyBinding(
KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK),
DefaultEditorKit.beepAction),
new JTextComponent.KeyBinding(
KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK),
DefaultEditorKit.beepAction)
};

Keymap k = ();

JTextComponent.loadKeymap(k, newBindings, mytextfield.getActions());
Keymap k1 = Obj_Name.getKeymap();
JTextComponent.loadKeymap(k1, newBindings, Obj_Name.getActions());

}

No comments:

Post a Comment