JLabel: setDisplayedMnemonicIndex(int index) : JLabel « javax.swing « Java by API






JLabel: setDisplayedMnemonicIndex(int index)

 


import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main {
  public static void main(String[] args) {
    JTextField firstField = new JTextField(10);
    JTextField middleField = new JTextField(10);
    JTextField lastField = new JTextField(10);

    JLabel firstLabel = new JLabel("First Name", JLabel.RIGHT);
    firstLabel.setDisplayedMnemonic('F');
    firstLabel.setLabelFor(firstField);

    JLabel middleLabel = new JLabel("Middle Initial", JLabel.RIGHT);
    middleLabel.setDisplayedMnemonic('I');
    middleLabel.setDisplayedMnemonicIndex(7);
    middleLabel.setLabelFor(middleField);

    JLabel lastLabel = new JLabel("Last Name", JLabel.RIGHT);
    lastLabel.setDisplayedMnemonic('L');
    lastLabel.setLabelFor(lastField);

    JPanel p = new JPanel();
    p.setLayout(new GridLayout(3, 2, 5, 5));
    p.add(firstLabel);
    p.add(firstField);
    p.add(middleLabel);
    p.add(middleField);
    p.add(lastLabel);
    p.add(lastField);

    JFrame f = new JFrame("MnemonicLabels");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(p);
    f.pack();
    f.setVisible(true);
  }
}

   
  








Related examples in the same category

1.JLabel.BOTTOM
2.JLabel.CENTER
3.JLabel.LEFT
4.JLabel.RIGHT
5.JLabel.TOP
6.new JLabel(Icon icon)
7.new JLabel(Icon i, int alignment)
8.new JLabel(String htmlString) (Multi-line Label)
9.new JLabel(String text, int horizontalAlignment)
10.new JLabel(String text, Icon icon, int horizontalAlignment)
11.JLabel: addMouseMotionListener(MouseMotionListener l)
12.JLabel: getTransferHandler()
13.JLabel: setBoder(Border border)
14.JLabel: setBounds(int x, int y, int width, int height)
15.JLabel: setDisplayedMnemonic(int key) (KeyEvent.VK_U)
16.JLabel: setLabelFor(Component c)
17.JLabel: setText(String str)
18.JLabel: setHorizontalTextPosition(int align)
19.JLabel: setIcon(Icon icon)
20.JLabel: setOpaque(boolean isOpaque)
21.JLabel: setPreferredSize(Dimension preferredSize)
22.JLabel: setToolTipText(String text)
23.JLabel: setVerticalAlignment(int alignment)
24.JLabel: setVerticalTextPosition(int align)
25.extends JLabel