Example usage for javax.swing JLabel setLabelFor

List of usage examples for javax.swing JLabel setLabelFor

Introduction

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

Prototype

@BeanProperty(description = "The component this is labelling.")
public void setLabelFor(Component c) 

Source Link

Document

Set the component this is labelling.

Usage

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

/**
 * Add a new Text Field/*from  w w w .  java  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//from   www .ja  va2  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 combo box (with label) to parent container
 * /*  w  w w.  ja  v a  2  s  .  c om*/
 * @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
 * /*from  www .j a va 2s  . c o  m*/
 * @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
 * //from  ww  w  .ja  v  a2  s  .  c  o  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.apache.cayenne.modeler.CayenneModelerFrame.java

/** Initializes main toolbar. */
protected void initToolbar() {
    JToolBar toolBar = new JToolBar();

    toolBar.add(getAction(NewProjectAction.class).buildButton());
    toolBar.add(getAction(OpenProjectAction.class).buildButton());
    toolBar.add(getAction(SaveAction.class).buildButton());

    toolBar.addSeparator();/*from   w w  w . java 2  s  . co  m*/
    toolBar.add(getAction(RemoveAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CutAction.class).buildButton());
    toolBar.add(getAction(CopyAction.class).buildButton());
    toolBar.add(getAction(PasteAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(UndoAction.class).buildButton());
    toolBar.add(getAction(RedoAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateNodeAction.class).buildButton());
    toolBar.add(getAction(CreateDataMapAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateDbEntityAction.class).buildButton());
    toolBar.add(getAction(CreateProcedureAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(CreateObjEntityAction.class).buildButton());
    toolBar.add(getAction(CreateEmbeddableAction.class).buildButton());
    toolBar.add(getAction(CreateQueryAction.class).buildButton());

    toolBar.addSeparator();

    toolBar.add(getAction(NavigateBackwardAction.class).buildButton());
    toolBar.add(getAction(NavigateForwardAction.class).buildButton());

    JPanel east = new JPanel(new BorderLayout()); // is used to place search feature
    // components the most right on a
    // toolbar
    final JTextField findField = new JTextField(10);
    findField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() != KeyEvent.VK_ENTER) {
                findField.setBackground(Color.white);
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    findField.setAction(getAction(FindAction.class));
    JLabel findLabel = new JLabel("Search:");
    findLabel.setLabelFor(findField);
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        public void eventDispatched(AWTEvent event) {

            if (event instanceof KeyEvent) {

                if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                        && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F) {
                    findField.requestFocus();
                }
            }
        }

    }, AWTEvent.KEY_EVENT_MASK);

    JPanel box = new JPanel(); // is used to place label and text field one after
    // another
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    box.add(findLabel);
    box.add(findField);
    east.add(box, BorderLayout.EAST);
    toolBar.add(east);

    getContentPane().add(toolBar, BorderLayout.NORTH);
}

From source file:org.apache.jmeter.protocol.http.config.gui.UrlConfigGui.java

private JPanel getPortPanel() {
    port = new JTextField(10);

    JLabel label = new JLabel(JMeterUtils.getResString("web_server_port")); // $NON-NLS-1$
    label.setLabelFor(port);

    JPanel panel = new JPanel(new BorderLayout(5, 0));
    panel.add(label, BorderLayout.WEST);
    panel.add(port, BorderLayout.CENTER);

    return panel;
}

From source file:org.apache.jmeter.protocol.http.config.gui.UrlConfigGui.java

private JPanel getProxyPortPanel() {
    proxyPort = new JTextField(10);

    JLabel label = new JLabel(JMeterUtils.getResString("web_server_port")); // $NON-NLS-1$
    label.setLabelFor(proxyPort);
    label.setFont(FONT_SMALL);//from   w w w . ja  v a  2  s  .c o  m

    JPanel panel = new JPanel(new BorderLayout(5, 0));
    panel.add(label, BorderLayout.WEST);
    panel.add(proxyPort, BorderLayout.CENTER);

    return panel;
}

From source file:org.apache.jmeter.protocol.http.config.gui.UrlConfigGui.java

private JPanel getConnectTimeOutPanel() {
    connectTimeOut = new JTextField(10);

    JLabel label = new JLabel(JMeterUtils.getResString("web_server_timeout_connect")); // $NON-NLS-1$
    label.setLabelFor(connectTimeOut);

    JPanel panel = new JPanel(new BorderLayout(5, 0));
    panel.add(label, BorderLayout.WEST);
    panel.add(connectTimeOut, BorderLayout.CENTER);

    return panel;
}

From source file:org.apache.jmeter.protocol.http.config.gui.UrlConfigGui.java

private JPanel getResponseTimeOutPanel() {
    responseTimeOut = new JTextField(10);

    JLabel label = new JLabel(JMeterUtils.getResString("web_server_timeout_response")); // $NON-NLS-1$
    label.setLabelFor(responseTimeOut);

    JPanel panel = new JPanel(new BorderLayout(5, 0));
    panel.add(label, BorderLayout.WEST);
    panel.add(responseTimeOut, BorderLayout.CENTER);

    return panel;
}