List of usage examples for javax.swing AbstractButton setText
@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.") public void setText(String text)
From source file:Main.java
/** * Uses the value returned via the component's getText() method to set a Mnemonic key. * The character following the first '&' charcater is used as Mnemonic key, * but this only works for characters in the range a..Z * If a Mnemonic key is found, the '&' character is removed from the text. * @param textComponent/*from w w w .j a v a2 s .c o m*/ */ public static void setMnemonic(AbstractButton textComponent) { String label = textComponent.getText(); if (label == null || label.isEmpty() || !label.contains("&") || label.indexOf('&') == label.length() - 1) { return; } char ch = label.charAt(label.indexOf('&') + 1); if (!Character.isLetter(ch)) { return; } int ke = getKeyEvent(ch); if (ke != Integer.MIN_VALUE) { label = label.substring(0, label.indexOf('&')) + label.substring(label.indexOf('&') + 1, label.length()); textComponent.setText(label); textComponent.setMnemonic(ke); } }
From source file:Main.java
public Main(JFrame frame) { analyzer = new MyDialog(frame); analyzer.pack();/* w w w . j a va 2 s . c o m*/ analyzer.setLocationRelativeTo(frame); Point location = analyzer.getLocation(); location = new Point(location.x - LOC_SHIFT, location.y - LOC_SHIFT); analyzer.setLocation(location); analyzer.setVisible(true); add(new JButton(new AbstractAction(DISABLE_DIALOG_COMPONENTS) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG_COMPONENTS)) { btn.setText(ENABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(false); } else { btn.setText(DISABLE_DIALOG_COMPONENTS); analyzer.setComponentEnabled(true); } } })); add(new JButton(new AbstractAction(DISABLE_DIALOG) { @Override public void actionPerformed(ActionEvent evt) { AbstractButton btn = (AbstractButton) evt.getSource(); if (btn.getText().equals(DISABLE_DIALOG)) { btn.setText(ENABLE_DIALOG); analyzer.setEnabled(false); } else { btn.setText(DISABLE_DIALOG); analyzer.setEnabled(true); } } })); }
From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java
private AbstractButton createHierarchyButton(ActionCommand command) { AbstractButton button = command.createButton(); button.setText(null); String iconKey = BeanUtil.beanName(command.getClass()) + ".bigicon"; button.setIcon(getIconSource().getIcon(iconKey)); return button; }
From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java
/** * @noinspection ALL/*from w w w . j av a 2s. c o m*/ */ private void $$$loadButtonText$$$(AbstractButton 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.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
From source file:apidemo.PanScrollZoomDemo.java
/** * Prepares a button./*from w ww .j a v a2 s .co m*/ * * @param button the button. * @param actionKey the action key. * @param buttonLabelText the button label. * @param toolTipText the tooltip text. */ private void prepareButton(final AbstractButton button, final String actionKey, final String buttonLabelText, final String toolTipText) { // todo // as this action is empty and the button text is // redefined later, it can be safely removed ... // Action action = new AbstractAction(actionKey) { // public void actionPerformed(ActionEvent evt) { // // ignored // } // }; // button.addActionListener(action); button.setActionCommand(actionKey); button.setText(buttonLabelText); button.setToolTipText(toolTipText); button.addActionListener(this); }
From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java
@Override public void layout() { // check type to see if it's a toggleButton if (type == Type.CHECKBOX || type == Type.RADIO) { final AbstractButton oldButton = getButton(); final AbstractButton button = new JToggleButton(); button.setText(oldButton.getText()); button.setIcon(oldButton.getIcon()); button.setEnabled(oldButton.isEnabled()); button.setSelected(this.selected); setButton(button);//from w w w. j a va 2 s. c o m if (this.getOnclick() != null) { this.setOnclick(this.getOnclick()); } } final AbstractButton button = getButton(); // adjust orientation of label and icon if (this.orientation == Orient.VERTICAL) { button.setHorizontalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setVerticalTextPosition(JButton.BOTTOM); } else { button.setVerticalTextPosition(JButton.TOP); } } else { button.setVerticalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setHorizontalTextPosition(JButton.RIGHT); } else { button.setHorizontalTextPosition(JButton.LEFT); } } // Square button patch. if no label and icon is square, set min/max to square up button final Icon icon = button.getIcon(); if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) { Dimension dim = button.getPreferredSize(); button.setMinimumSize(new Dimension(dim.height, dim.height)); button.setPreferredSize(new Dimension(dim.height, dim.height)); } button.setToolTipText(this.getTooltiptext()); super.layout(); }
From source file:org.springframework.richclient.core.LabelInfo.java
/** * Configures the given button with the properties held in this instance. Note that this * instance doesn't hold any keystroke accelerator information. * * @param button The button to be configured. * * @throws IllegalArgumentException if {@code button} is null. *//*from w w w. jav a2s . c o m*/ public void configureButton(AbstractButton button) { Assert.notNull(button); button.setText(this.text); button.setMnemonic(getMnemonic()); button.setDisplayedMnemonicIndex(getMnemonicIndex()); }