List of utility methods to do JButton Settings
void | setButtonInsetsRecursive(Insets insets, Container container) set Button Insets Recursive Component[] components = container.getComponents(); for (int i = 0; i < components.length; i++) { Component c = components[i]; if (c instanceof JButton || c instanceof JToggleButton) { if (!(c instanceof JCheckBox) && !(c instanceof JRadioButton)) ((AbstractButton) c).setMargin(insets); } else if (c instanceof Container) setButtonInsetsRecursive(insets, (Container) c); ... |
void | setButtonSelected(ButtonGroup buttonGroup, int selected) set Button Selected ArrayList<AbstractButton> buttons = Collections.list(buttonGroup.getElements()); if (buttons.isEmpty()) return; if (selected < 0 || selected >= buttons.size()) selected = 0; AbstractButton buttonSelected = buttons.get(selected); buttonSelected.setSelected(true); ActionEvent actionEvent = new ActionEvent(buttonSelected, ActionEvent.ACTION_PERFORMED, ... |
void | setButtonStyle(AbstractButton btn) set Button Style getBasicFont(); btn.setFont(BASIC_FONT); btn.setForeground(BASIC_BUTTON_COLOR); btn.setBackground(BACKGROUND); |
void | setButtonText(ButtonGroup buttonGroup, List setter method for button text. int index = 0; for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) { AbstractButton button = buttons.nextElement(); button.setText(texts.get(index).toString()); index++; |
void | setHelpIDString(javax.swing.AbstractButton btn, String id) set Help ID String btn.putClientProperty("HelpID", id);
|
void | setHorizontalMargin(AbstractButton button, int hMargin) Sets the left and right margin of an AbstractButton in a L&F-independent manner (some L&Fs set this value in the margin, while others ignore this property and use the border instead). Insets margin = button.getMargin();
margin.left = margin.right = hMargin;
Border empty = BorderFactory.createEmptyBorder(margin.top, margin.left, margin.bottom, margin.right);
Border outer = button.getBorder();
Border compound = BorderFactory.createCompoundBorder(outer, empty);
button.setMargin(new Insets(0, 0, 0, 0));
button.setBorder(compound);
|
void | setImageIcon(AbstractButton abstractButton, URL url) set Image Icon if (url != null) { abstractButton.setIcon(new ImageIcon(url)); } else { abstractButton.setIcon(null); |
void | setMnemonic(AbstractButton actionComponent) Translate the character following MNEMONIC_CHARACTER in the label by a mnemonic String componentLabel = actionComponent.getText(); int charPosition = getMnemonicCharPos(componentLabel); if (charPosition >= 0) { actionComponent.setMnemonic(Character.toUpperCase(componentLabel.charAt(charPosition + 1))); actionComponent.setText(clearMnemonic(charPosition, componentLabel)); |
void | setPreferredWidth(JComponent button, int minWidth) Sets the minimum width of a JButton . Dimension size = button.getPreferredSize();
if (size.width < minWidth) {
size.width = minWidth;
button.setPreferredSize(size);
|
boolean | setRadioButtonSelected(Window window, String buttonText) set Radio Button Selected final JRadioButton rb = findRadioButton(window, buttonText); if (rb == null) return false; if (rb.isSelected()) return true; rb.doClick(); return true; |