Example usage for javax.swing JLabel setDisplayedMnemonic

List of usage examples for javax.swing JLabel setDisplayedMnemonic

Introduction

In this page you can find the example usage for javax.swing JLabel setDisplayedMnemonic.

Prototype

public void setDisplayedMnemonic(char aChar) 

Source Link

Document

Specifies the displayedMnemonic as a char value.

Usage

From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java

/**
 * @noinspection ALL//from   w w  w  .  j  a va 2s  . c o m
 */
private void $$$loadLabelText$$$(JLabel component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length())
                break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setDisplayedMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a new Text Field//from  w w  w .j  a v a 2  s .  c om
 * 
 * @param container - parent container
 * @param name - name of text field
 * @param initialValue - initial value of text field
 * @param mnemonic - mnemonic key
 * @param tooltip - tool tip for field
 * @param suffix - suffix text for field
 * @param labelWidth - label width 
 * @param placement - TableLayout placement
 * @param debug - turn on/off red debug borders
 * @return JTextField
 */
public static JTextField addTextField(Container container, String name, String initialValue, int mnemonic,
        String tooltip, String suffix, double labelWidth, String placement, boolean debug) {

    double[][] size = null;

    JPanel panel = new JPanel();
    panel.setOpaque(false);

    if (suffix.equals(""))
        size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } };
    else
        size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } };

    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JLabel label = new JLabel(name);
    label.setDisplayedMnemonic(mnemonic);
    JTextField result = new JTextField(20);
    label.setLabelFor(result);
    label.setOpaque(false);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(label, "0, 0, r, c");
    panel.add(result, "1, 0, f, c");

    if (suffix.length() != 0) {
        JLabel suffixLabel = new JLabel(" " + suffix);
        panel.add(suffixLabel, "2,0, l, c");
    }

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    container.add(panel, placement);
    return result;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a new Password Text Field/* ww w . j  a v a 2 s  .  c  om*/
 * 
 * @param container - parent container
 * @param name - name of text field
 * @param initialValue - initial value of text field
 * @param mnemonic - mnemonic key
 * @param tooltip - tool tip for field
 * @param suffix - suffix text for field
 * @param labelWidth - label width 
 * @param placement - TableLayout placement
 * @param debug - turn on/off red debug borders
 * @return JPasswordField
 */
public static JPasswordField addPasswordField(Container container, String name, String initialValue,
        int mnemonic, String tooltip, String suffix, double labelWidth, String placement, boolean debug) {

    double[][] size = null;

    JPanel panel = new JPanel();
    panel.setOpaque(false);

    if (suffix.equals(""))
        size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } };
    else
        size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } };

    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JLabel label = new JLabel(name);
    label.setDisplayedMnemonic(mnemonic);

    JPasswordField result = new JPasswordField(20);
    label.setLabelFor(result);
    label.setOpaque(false);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(label, "0, 0, r, c");
    panel.add(result, "1, 0, f, c");

    if (suffix.length() != 0) {
        JLabel suffixLabel = new JLabel(" " + suffix);
        panel.add(suffixLabel, "2,0, l, c");
    }

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    container.add(panel, placement);
    return result;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a TextArea that has scrolling functionality
 * /* w ww .j  a va 2  s . co  m*/
 * @param container - parent container
 * @param name - name of text area
 * @param text - text to put in text area
 * @param mnemonic - mnemonic key
 * @param placement - TableLayout placement in parent container
 * @param debug - turn on/off red debug borders
 * @return JTextArea
 */
public static JTextArea addScrollingTextArea(Container container, String name, String text, int mnemonic,
        String placement, boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double size[][] = { { TableLayout.FILL }, { 20, TableLayout.FILL } };
    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JTextArea textArea = new JTextArea();
    textArea.setLineWrap(true);
    textArea.setOpaque(true);

    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    if (debug == true)
        panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                panel.getBorder()));

    if (!name.equals("")) {
        JLabel label = new JLabel(name);
        label.setOpaque(false);
        label.setDisplayedMnemonic(mnemonic);
        panel.add(label, "0, 0, l, c");
        panel.add(areaScrollPane, "0, 1, f, f");
    } else {
        panel.add(areaScrollPane, "0, 0, 0, 1");
    }

    container.add(panel, placement);

    return textArea;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a combo box (with label) to parent container
 * /*from  w w  w.  ja  va  2 s. c  o  m*/
 * @param container - parent container
 * @param label - combo box label
 * @param initialValues - initial value for combo box
 * @param mnemonic - combo box mnemonic
 * @param tooltip - tool tip for combo box
 * @param labelWidth - width of label
 * @param placement - TableLayout placement in parent container
 * @param debug - turn on/off red debug borders
 * @return JComboBox
 */
public static JComboBox addComboBox(Container container, String label, Object[] initialValues, int mnemonic,
        String tooltip, double labelWidth, String placement, boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double size[][] = { { labelWidth, TableLayout.FILL }, { TableLayout.PREFERRED } };
    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);

    JLabel labelTxt = new JLabel(label);
    labelTxt.setDisplayedMnemonic(mnemonic);
    panel.add(labelTxt, "0,0,L,C");

    JComboBox result = null;
    if (initialValues != null) {
        result = new JComboBox(initialValues);
    } else {
        result = new JComboBox();
    }
    labelTxt.setLabelFor(result);
    result.setToolTipText(tooltip);
    panel.add(result, "1,0,F,C");
    container.add(panel, placement);
    result.setOpaque(false);
    return result;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a whole number field to the parent container
 * /*  www.  j a  v a 2s  .  c om*/
 * @param container - parent container 
 * @param prefexStr - prefix text for field
 * @param initialValue - intial field value
 * @param suffexStr - suffex for field
 * @param mnemonic - accellerator key menonic
 * @param tooltip - tool tip for field
 * @param maxChars - maximum characters in field
 * @param fieldWidth - width of field
 * @param placement - TableLayout placement of field in parent container
 * @param debug - red debug border on/off
 * @return WholeNumberField
 */
public static WholeNumberField addWholeNumberField(Container container, String prefexStr, String initialValue,
        String suffexStr, int mnemonic, String tooltip, int maxChars, int fieldWidth, String placement,
        boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double table[][] = { { TableLayout.PREFERRED, fieldWidth, 5, TableLayout.PREFERRED }, // columns
            { TableLayout.PREFERRED } }; // rows 

    TableLayout layout = new TableLayout(table);
    panel.setLayout(layout);

    JLabel prefex = new JLabel(prefexStr);
    prefex.setDisplayedMnemonic(mnemonic);
    panel.add(prefex, "0,0");

    WholeNumberField result = new WholeNumberField(0, maxChars);
    result.setHorizontalAlignment(JTextField.CENTER);
    prefex.setLabelFor(result);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(result, "1,0");

    JLabel suffex = new JLabel(suffexStr);
    panel.add(suffex, "3,0");

    container.add(panel, placement);

    return result;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a text field that only allows decimal numbers to be entered
 * //  w  ww  .  ja  v a2 s.co  m
 * @param container - parent container
 * @param prefexStr - prefix string for the text field
 * @param initialValue - initial decimal value
 * @param suffexStr - suffix string for the text field
 * @param mnemonic - accellerator key nmemonic
 * @param tooltip - tooltip for the field
 * @param maxChars - max length for the field
 * @param fieldWidth - width for the field
 * @param placement - TableLayout placement in parent container
 * @param debug - turn debug red borders on/off
 * @return DecimalNumberField
 */
public static DecimalNumberField addDecimalNumberField(Container container, String prefexStr,
        String initialValue, String suffexStr, int mnemonic, String tooltip, int maxChars, int fieldWidth,
        String placement, boolean debug) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double table[][] = { { TableLayout.PREFERRED, fieldWidth, 5, TableLayout.PREFERRED }, // columns
            { TableLayout.PREFERRED } }; // rows 

    TableLayout layout = new TableLayout(table);
    panel.setLayout(layout);

    JLabel prefex = new JLabel(prefexStr);
    prefex.setDisplayedMnemonic(mnemonic);
    panel.add(prefex, "0,0");

    DecimalNumberField result = new DecimalNumberField(null, maxChars);
    result.setHorizontalAlignment(JTextField.CENTER);
    prefex.setLabelFor(result);
    result.setToolTipText(tooltip);
    if (initialValue != null)
        result.setText(initialValue);

    panel.add(result, "1,0");

    JLabel suffex = new JLabel(suffexStr);
    panel.add(suffex, "3,0");

    container.add(panel, placement);

    return result;
}

From source file:org.executequery.gui.editor.QueryEditor.java

private JLabel createLabel(String text, char mnemonic) {

    final JLabel label = new JLabel(text);
    label.setDisplayedMnemonic(mnemonic);

    return label;
}

From source file:org.javaswift.cloudie.CloudiePanel.java

public JMenuBar createMenuBar() {
    JMenuBar bar = new JMenuBar();
    JMenu accountMenu = new JMenu("Account");
    JMenu containerMenu = new JMenu("Container");
    JMenu storedObjectMenu = new JMenu("StoredObject");
    JMenu helpMenu = new JMenu("Help");
    accountMenu.setMnemonic('A');
    containerMenu.setMnemonic('C');
    storedObjectMenu.setMnemonic('O');
    helpMenu.setMnemonic('H');
    bar.add(accountMenu);/*from  ww w . j ava  2 s  .c om*/
    bar.add(containerMenu);
    bar.add(storedObjectMenu);
    bar.add(helpMenu);
    JPanel panel = new JPanel(new FlowLayout(SwingConstants.RIGHT, 0, 0));
    JLabel label = new JLabel(getIcon("zoom.png"));
    label.setLabelFor(searchTextField);
    label.setDisplayedMnemonic('f');
    panel.add(label);
    panel.add(searchTextField);
    bar.add(panel);
    //
    accountMenu.add(new JMenuItem(accountLoginAction));
    accountMenu.add(new JMenuItem(accountLogoutAction));
    accountMenu.addSeparator();
    accountMenu.add(new JMenuItem(accountQuitAction));
    //
    containerMenu.add(new JMenuItem(containerRefreshAction));
    containerMenu.add(new JMenuItem(containerViewMetaData));
    containerMenu.addSeparator();
    containerMenu.add(new JMenuItem(containerCreateAction));
    containerMenu.add(new JMenuItem(containerDeleteAction));
    containerMenu.addSeparator();
    containerMenu.add(new JMenuItem(containerEmptyAction));
    containerMenu.addSeparator();
    containerMenu.add(new JMenuItem(containerPurgeAction));
    //
    storedObjectMenu.add(new JMenuItem(storedObjectPreviewAction));
    storedObjectMenu.add(new JMenuItem(storedObjectOpenAction));
    storedObjectMenu.add(new JMenuItem(storedObjectViewMetaData));
    storedObjectMenu.addSeparator();
    storedObjectMenu.add(new JMenuItem(storedObjectCreateAction));
    storedObjectMenu.add(new JMenuItem(storedObjectDownloadAction));
    storedObjectMenu.addSeparator();
    storedObjectMenu.add(new JMenuItem(storedObjectDeleteAction));
    //
    helpMenu.add(new JMenuItem(aboutAction));
    //
    return bar;
}

From source file:org.openmicroscopy.shoola.util.ui.MessengerDialog.java

/**
 * Builds and lays out the panel hosting the <code>comment</code> details.
 * //from  w  w  w  .  j a  va2  s .c o m
 * @param comment      The comment's text.
 * @param mnemonic       The key-code that indicates a mnemonic key.
 * @return See above.
 */
private JPanel buildCommentAreaPanel(String comment, int mnemonic) {
    JPanel panel = new JPanel();
    panel.setOpaque(false);

    double size[][] = { { TableLayout.FILL }, { 20, TableLayout.FILL } };
    TableLayout layout = new TableLayout(size);
    panel.setLayout(layout);
    JScrollPane areaScrollPane = new JScrollPane(commentArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    JLabel label = new JLabel(comment);
    label.setOpaque(false);
    label.setDisplayedMnemonic(mnemonic);
    panel.add(label, "0, 0, LEFT, CENTER");
    panel.add(areaScrollPane, "0, 1");
    return panel;
}