Example usage for javax.swing.text Keymap removeKeyStrokeBinding

List of usage examples for javax.swing.text Keymap removeKeyStrokeBinding

Introduction

In this page you can find the example usage for javax.swing.text Keymap removeKeyStrokeBinding.

Prototype

public void removeKeyStrokeBinding(KeyStroke keys);

Source Link

Document

Removes a binding from the keymap.

Usage

From source file:DefaultSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Default Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField();
    frame.add(textField, BorderLayout.NORTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand() + " selected");
        }//from ww w.ja v  a 2 s  .c  o  m
    };
    JPanel panel = new JPanel();
    JButton defaultButton = new JButton("Default Button");
    defaultButton.addActionListener(actionListener);
    panel.add(defaultButton);

    JButton otherButton = new JButton("Other Button");
    otherButton.addActionListener(actionListener);
    panel.add(otherButton);

    frame.add(panel, BorderLayout.SOUTH);

    Keymap keymap = textField.getKeymap();
    KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    keymap.removeKeyStrokeBinding(keystroke);

    frame.getRootPane().setDefaultButton(defaultButton);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:DefaultSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Default Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();

    JTextField textField = new JTextField();
    content.add(textField, BorderLayout.NORTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand() + " selected");
        }/*from ww w .j  av a2s. co m*/
    };

    JPanel panel = new JPanel();
    JButton defaultButton = new JButton("Default Button");
    defaultButton.addActionListener(actionListener);
    panel.add(defaultButton);

    JButton otherButton = new JButton("Other Button");
    otherButton.addActionListener(actionListener);
    panel.add(otherButton);

    content.add(panel, BorderLayout.SOUTH);

    Keymap keymap = textField.getKeymap();
    KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    keymap.removeKeyStrokeBinding(keystroke);

    frame.getRootPane().setDefaultButton(defaultButton);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Default Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField();
    frame.add(textField, BorderLayout.NORTH);

    JPanel panel = new JPanel();
    JButton defaultButton = new JButton("Default Button");
    defaultButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand() + " selected");
        }//from  www  .  j a v  a2  s .c  o  m
    });
    panel.add(defaultButton);

    JButton otherButton = new JButton("Other Button");
    otherButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand() + " selected");
        }
    });
    panel.add(otherButton);

    frame.add(panel, BorderLayout.SOUTH);

    Keymap keymap = textField.getKeymap();
    KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    keymap.removeKeyStrokeBinding(keystroke);

    frame.getRootPane().setDefaultButton(defaultButton);

    frame.setSize(250, 150);
    frame.setVisible(true);

}

From source file:PassiveTextField1.java

public static void main(String[] args) {
    JFrame f = new JFrame("Passive Text Field");
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    final JTextField ptf = new JTextField(32);
    JTextField tf = new JTextField(32);
    JPanel p = new JPanel();
    JButton b = new JButton("OK");
    p.add(b);/*from w  w w .j a va  2s  . co  m*/
    f.getContentPane().add(ptf);
    f.getContentPane().add(tf);
    f.getContentPane().add(p);

    Keymap map = ptf.getKeymap(); // Gets the shared map
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    map.removeKeyStrokeBinding(key);

    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Action event from a text field");
        }
    };
    ptf.addActionListener(l);
    tf.addActionListener(l);

    // Make the button the default button
    f.getRootPane().setDefaultButton(b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Content of text field: <" + ptf.getText() + ">");
        }
    });
    f.pack();
    f.setVisible(true);
}