Java Utililty Methods JButton Settings

List of utility methods to do JButton Settings

Description

The list of methods to do JButton Settings are organized into topic(s).

Method

InsetsgetDefaultFatButtonMargin()
get Default Fat Button Margin
if (isGTKLaF()) {
    return new Insets(0, 2, 0, 2);
return new Insets(2, 4, 2, 4);
intgetHudControlShadowSize(AbstractButton button)
Gets the number of pixels that a HUD style widget's shadow takes up.
return 2;
IcongetIcon(AbstractButton b)
Returns the current icon for the specified button.
Icon icon = b.getIcon();
if (icon == null)
    return null;
ButtonModel model = b.getModel();
Icon tmpIcon = null;
if (icon != null) {
    if (!model.isEnabled()) {
        if (model.isSelected()) {
...
ListgetListenedButtonsFor(Container c)
get Listened Buttons For
List<JButton> filter = null;
List<JButton> result = new ArrayList<JButton>();
searchFor(c, JButton.class, filter = new ArrayList<JButton>(), null);
for (JButton button : filter) {
    if (button.getActionListeners().length > 0) {
        result.add(button);
return result;
JButtongetMonospaceButton(final String text, final int size)
Returns a JButton with monospaced text.
Font font = new Font(Font.MONOSPACED, Font.PLAIN, size);
JButton button = new JButton(text);
button.setFont(font);
return button;
DimensiongetPreferredButtonSize(AbstractButton b, int textIconGap)
Determines the preferred width and height of an AbstractButton, given the gap between the button’s text and icon.
Rectangle contentRect;
Rectangle viewRect;
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Insets insets = b.getInsets();
Insets margin = b.getMargin();
viewRect = new Rectangle(0, 0,  Integer.MAX_VALUE,  Integer.MAX_VALUE);
SwingUtilities.layoutCompoundLabel(b, 
...
DimensiongetPreferredButtonSize(AbstractButton b, int textIconGap)
get Preferred Button Size
if (b.getComponentCount() > 0) {
    return null;
Icon icon = (Icon) b.getIcon();
String text = b.getText();
Font font = b.getFont();
FontMetrics fm = b.getFontMetrics(font);
Rectangle iconR = new Rectangle();
...
ImageIcongetPressedButtonIcon(int x, int y)
get Pressed Button Icon
if (PressedButton == null) {
    PressedButton = new ImageIcon(IMAGE_FOLDER + PRESSED_BUTTON_IMAGE);
return prepareImage(PressedButton, x, y);
BordergetRadioButtonBorder(int fontSize, boolean ltr)
Returns the border for radio buttons under the specified font size.
Border checkBoxBorder = getCheckBoxBorder(fontSize, ltr);
Insets checkBoxInsets = checkBoxBorder.getBorderInsets(null);
return new BorderUIResource.EmptyBorderUIResource(checkBoxInsets.top, checkBoxInsets.left - (ltr ? 0 : 2),
        checkBoxInsets.bottom, checkBoxInsets.right - (ltr ? 2 : 0));
AbstractButtongetSelectedButton(ButtonGroup group)
get Selected Button
Enumeration<AbstractButton> buttons = group.getElements();
while (buttons.hasMoreElements()) {
    AbstractButton button = buttons.nextElement();
    if (button.isSelected()) {
        return button;
return null;
...