List of usage examples for javax.swing JLabel setDisplayedMnemonicIndex
@BeanProperty(visualUpdate = true, description = "the index into the String to draw the keyboard character mnemonic at") public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException
From source file:Main.java
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);/*from w w w. j a v a2 s. c om*/ 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); }
From source file:bazaar4idea.ui.BzrPushDialog.java
/** Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * @noinspection ALL//from w w w. j ava 2s . c o m */ private void $$$setupUI$$$() { contentPanel = new JPanel(); contentPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); final JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 0), -1, -1)); contentPanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); final Spacer spacer1 = new Spacer(); panel1.add(spacer1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); final JLabel label1 = new JLabel(); label1.setText("Destination Repository URL:"); label1.setDisplayedMnemonic('D'); label1.setDisplayedMnemonicIndex(0); panel1.add(label1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); repositoryTxt = new JTextField(); panel1.add(repositoryTxt, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1)); panel1.add(panel2, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, new Dimension(-1, 100), null, null, 0, false)); panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Options")); revisionCbx = new JCheckBox(); revisionCbx.setText("Revision"); revisionCbx.setMnemonic('R'); revisionCbx.setDisplayedMnemonicIndex(0); panel2.add(revisionCbx, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); revisionTxt = new JTextField(); revisionTxt.setEnabled(false); revisionTxt.setText("tip"); panel2.add(revisionTxt, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final Spacer spacer2 = new Spacer(); panel2.add(spacer2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); final Spacer spacer3 = new Spacer(); panel2.add(spacer3, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); hgRepositorySelectorComponent = new BzrRepositorySelectorComponent(); panel1.add(hgRepositorySelectorComponent.$$$getRootComponent$$$(), new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); label1.setLabelFor(repositoryTxt); }
From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java
/** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * * @noinspection ALL//from w ww .j a v a 2 s .c o m */ private void $$$setupUI$$$() { rootComponent = new JPanel(); rootComponent.setLayout(new GridBagLayout()); final JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayoutManager(7, 3, new Insets(0, 0, 0, 0), -1, -1)); GridBagConstraints gbc; gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.BOTH; rootComponent.add(panel1, gbc); serverName = new JTextField(); serverName.setText(""); panel1.add(serverName, new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label1 = new JLabel(); label1.setHorizontalAlignment(4); label1.setHorizontalTextPosition(4); label1.setText("Server Name:"); label1.setDisplayedMnemonic('S'); label1.setDisplayedMnemonicIndex(0); panel1.add(label1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(80, -1), new Dimension(92, 16), null, 0, false)); serverUrl = new JTextField(); panel1.add(serverUrl, new GridConstraints(2, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); username = new JTextField(); panel1.add(username, new GridConstraints(3, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); password = new JPasswordField(); panel1.add(password, new GridConstraints(4, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label2 = new JLabel(); label2.setHorizontalAlignment(4); label2.setText("Server URL:"); label2.setDisplayedMnemonic('U'); label2.setDisplayedMnemonicIndex(7); panel1.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(80, -1), new Dimension(92, 16), null, 0, false)); final JLabel label3 = new JLabel(); label3.setHorizontalAlignment(4); label3.setText("Username:"); label3.setDisplayedMnemonic('N'); label3.setDisplayedMnemonicIndex(4); panel1.add(label3, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(92, 16), null, 0, false)); final JLabel label4 = new JLabel(); label4.setHorizontalAlignment(4); label4.setText("Password:"); label4.setDisplayedMnemonic('P'); label4.setDisplayedMnemonicIndex(0); panel1.add(label4, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(92, 16), null, 0, false)); testConnection = new JButton(); testConnection.setText("Test Connection"); testConnection.setMnemonic('T'); testConnection.setDisplayedMnemonicIndex(0); panel1.add(testConnection, new GridConstraints(5, 2, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); // chkPasswordRemember = new JCheckBox(); // chkPasswordRemember.setSelected(true); // chkPasswordRemember.setText("Remember Password"); // chkPasswordRemember.setMnemonic('R'); // chkPasswordRemember.setDisplayedMnemonicIndex(0); // panel1.add(chkPasswordRemember, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, // GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, // null, null, null, 0, false)); cbEnabled = new JCheckBox(); cbEnabled.setEnabled(false); cbEnabled.setHorizontalTextPosition(11); cbEnabled.setText("Server Enabled"); cbEnabled.setMnemonic('E'); cbEnabled.setDisplayedMnemonicIndex(7); panel1.add(cbEnabled, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(115, 25), null, 0, false)); useDefault = new JCheckBox(); useDefault.setText("Use Default Credentials"); panel1.add(useDefault, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JPanel spacer1 = new JPanel(); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.VERTICAL; rootComponent.add(spacer1, gbc); label1.setLabelFor(serverName); label2.setLabelFor(serverUrl); label3.setLabelFor(username); label4.setLabelFor(password); }
From source file:com.eviware.soapui.support.components.SimpleForm.java
private <T extends JComponent> T append(String name, JComponent label, T component, String alignments, int column, int columnSpan) { int spaceRowIndex = -1; if (rowSpacing > 0 && appended) { addSpace(rowSpacing);/* w w w. ja v a 2 s .com*/ spaceRowIndex = layout.getRowCount(); } layout.appendRow(rowSpec); int row = layout.getRowCount(); if (label != null) { panel.add(label, cc.xy(DEFAULT_LABEL_COLUMN, row)); component.addComponentListener(new LabelHider(label, spaceRowIndex)); component.addPropertyChangeListener(ENABLED_PROPERTY_NAME, new LabelEnabler(label)); if (label instanceof JLabel) { JLabel jl = ((JLabel) label); jl.setLabelFor(component); String text = jl.getText(); int ix = text.indexOf('&'); if (ix >= 0) { jl.setText(text.substring(0, ix) + text.substring(ix + 1)); jl.setDisplayedMnemonicIndex(ix); jl.setDisplayedMnemonic(text.charAt(ix + 1)); } if (component.getAccessibleContext() != null) { component.getAccessibleContext().setAccessibleName(text); } } } else { component.addComponentListener(new LabelHider(null, spaceRowIndex)); } addComponentToRow(name, component, alignments, column, row, columnSpan); return component; }
From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java
/** * @noinspection ALL//from w w w. ja v a 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:org.springframework.richclient.core.LabelInfo.java
/** * Configures the given label with the parameters from this instance. * * @param label The label that is to be configured. * @throws IllegalArgumentException if {@code label} is null. *//* w ww . j a va 2 s . com*/ public void configureLabel(JLabel label) { Assert.required(label, "label"); label.setText(this.text); label.setDisplayedMnemonic(getMnemonic()); if (getMnemonicIndex() >= -1) { label.setDisplayedMnemonicIndex(getMnemonicIndex()); } }