Example usage for java.awt.event KeyEvent VK_U

List of usage examples for java.awt.event KeyEvent VK_U

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_U.

Prototype

int VK_U

To view the source code for java.awt.event KeyEvent VK_U.

Click Source Link

Document

Constant for the "U" key.

Usage

From source file:KeymapExample.java

public static void main(String[] args) {
    JTextArea area = new JTextArea(6, 32);
    Keymap parent = area.getKeymap();
    Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent);

    KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK);
    Action actionU = new UpWord();
    newmap.addActionForKeyStroke(u, actionU);

    Action actionList[] = area.getActions();
    Hashtable lookup = new Hashtable();
    for (int j = 0; j < actionList.length; j += 1)
        lookup.put(actionList[j].getValue(Action.NAME), actionList[j]);

    KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK);
    Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction);
    newmap.addActionForKeyStroke(L, actionL);

    KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK);
    Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction);
    newmap.addActionForKeyStroke(W, actionW);

    area.setKeymap(newmap);/*  w ww.j a  v a2 s.  com*/

    JFrame f = new JFrame("KeymapExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
    area.setText("www.\n java2s \n .com.");
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("LabelFor Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Username");
    JTextField textField = new JTextField();
    label.setDisplayedMnemonic(KeyEvent.VK_U);
    label.setLabelFor(textField);//ww w . j av  a  2  s .  c  o m
    Container box = Box.createHorizontalBox();
    box.add(label);
    box.add(textField);
    frame.add(box, BorderLayout.NORTH);
    frame.add(new JButton("Submit"), BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);//from ww w  . j a  va  2s.  c  om
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    System.out.println(userLabel.getDisplayedMnemonicIndex());

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);/*from   ww  w .java 2s. c o m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    System.out.println(userLabel.getDisplayedMnemonic());

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);/*ww  w  .j a va  2 s.c om*/
    frame.setVisible(true);
}

From source file:Main.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    System.out.println(userLabel.getHorizontalAlignment());

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic('p');
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);// w  w  w  . j a v  a2s  .c  om
    frame.setVisible(true);
}

From source file:MainClass.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic(KeyEvent.VK_P);
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    frame.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);/*from  w w w  .ja  v  a2 s . co  m*/
    frame.setVisible(true);
}

From source file:LabelFor.java

public static void main(String args[]) {
    JFrame f = new JFrame("LabelFor Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JLabel label = new JLabel("Username");
    JTextField textField = new JTextField();
    label.setDisplayedMnemonic(KeyEvent.VK_U);
    label.setLabelFor(textField);//ww w .ja  v a2  s.  co m
    Container box = Box.createHorizontalBox();
    box.add(label);
    box.add(textField);
    content.add(box, BorderLayout.NORTH);
    content.add(new JButton("Submit"), BorderLayout.SOUTH);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:PasswordFieldSample.java

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

    JPanel userPanel = new JPanel(new BorderLayout());
    JLabel userLabel = new JLabel("Username: ");
    userLabel.setDisplayedMnemonic(KeyEvent.VK_U);
    JTextField userTextField = new JTextField();
    userLabel.setLabelFor(userTextField);
    userPanel.add(userLabel, BorderLayout.WEST);
    userPanel.add(userTextField, BorderLayout.CENTER);

    JPanel passPanel = new JPanel(new BorderLayout());
    JLabel passLabel = new JLabel("Password: ");
    passLabel.setDisplayedMnemonic(KeyEvent.VK_P);
    JPasswordField passTextField = new JPasswordField();
    passLabel.setLabelFor(passTextField);
    passPanel.add(passLabel, BorderLayout.WEST);
    passPanel.add(passTextField, BorderLayout.CENTER);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(userPanel, BorderLayout.NORTH);
    panel.add(passPanel, BorderLayout.SOUTH);
    content.add(panel, BorderLayout.NORTH);

    frame.setSize(250, 150);//from  w  ww  .j  a va  2 s.  c  om
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextArea area = new JTextArea(6, 32);
    Keymap parent = area.getKeymap();
    Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent);

    KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK);
    Action actionU = new UppercaseAction();
    newmap.addActionForKeyStroke(u, actionU);

    Action actionList[] = area.getActions();
    Hashtable lookup = new Hashtable();
    for (int j = 0; j < actionList.length; j += 1)
        lookup.put(actionList[j].getValue(Action.NAME), actionList[j]);

    KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK);
    Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction);
    newmap.addActionForKeyStroke(L, actionL);

    area.setKeymap(newmap);/*from www .j a v  a  2  s . c  o m*/

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JScrollPane(area), BorderLayout.CENTER);
    area.setText("this is a test");
    f.setSize(300, 300);
    f.setVisible(true);
}