KeyEvent.VK_B : KeyEvent « java.awt.event « Java by API






KeyEvent.VK_B

 
import java.awt.Event;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;

public class MainClass extends JFrame {
  MainClass(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel jp = new JPanel();

    JLabel jl = new JLabel("Name:");
    jp.add(jl);

    JTextField jt = new JTextField(20);
    jp.add(jt);

    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK);

    jt.getInputMap().put(ks, DefaultEditorKit.beepAction);

    getContentPane().add(jp);

    pack();
    setVisible(true);
  }

  public static void main(String[] args) {
    new MainClass("Binding Demo2");
  }
}

           
         
  








Related examples in the same category

1.KeyEvent.KEY_LOCATION_LEFT
2.KeyEvent.KEY_LOCATION_NUMPAD
3.KeyEvent.KEY_LOCATION_RIGHT
4.KeyEvent.KEY_LOCATION_STANDARD
5.KeyEvent.KEY_TYPED
6.KeyEvent.VK_DOWN
7.KeyEvent.VK_LEFT
8.KeyEvent.VK_N
9.KeyEvent.VK_RIGHT
10.KeyEvent.VK_U
11.KeyEvent.VK_UP
12.KeyEvent: getKeyChar()
13.KeyEvent: getKeyCode()
14.KeyEvent: getKeyLocation()
15.KeyEvent: getKeyText(int keyCode)
16.KeyEvent: isActionKey()