Example usage for javax.swing AbstractButton setMargin

List of usage examples for javax.swing AbstractButton setMargin

Introduction

In this page you can find the example usage for javax.swing AbstractButton setMargin.

Prototype

@BeanProperty(visualUpdate = true, description = "The space between the button's border and the label.")
public void setMargin(Insets m) 

Source Link

Document

Sets space for margin between the button's border and the label.

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");
    jb.setMargin(new Insets(5, 5, 5, 5));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);/*from  ww w .  ja va  2 s. c o m*/
    f.pack();
    f.setVisible(true);
}

From source file:org.openscience.jmol.app.Jmol.java

/**
 * Create a button to go inside of the toolbar.  By default this
 * will load an image resource.  The image filename is relative to
 * the classpath (including the '.' directory if its a part of the
 * classpath), and may either be in a JAR file or a separate file.
 *
 * @param key The key in the resource file to serve as the basis
 *  of lookups.//w  ww .j  a v  a2 s  . c  o  m
 * @return Button
 */
protected AbstractButton createToolbarButton(String key) {

    ImageIcon ii = JmolResourceHandler.getIconX(key + "Image");
    AbstractButton b = new JButton(ii);
    String isToggleString = JmolResourceHandler.getStringX(key + "Toggle");
    if (isToggleString != null) {
        boolean isToggle = Boolean.valueOf(isToggleString).booleanValue();
        if (isToggle) {
            b = new JToggleButton(ii);
            if (key.equals("rotate"))
                buttonRotate = b;
            toolbarButtonGroup.add(b);
            String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected");
            if (isSelectedString != null) {
                boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue();
                b.setSelected(isSelected);
            }
        }
    }
    b.setRequestFocusEnabled(false);
    b.setMargin(new Insets(1, 1, 1, 1));

    Action a = null;
    String actionCommand = null;
    if (key.endsWith("Script")) {
        actionCommand = JmolResourceHandler.getStringX(key);
        a = executeScriptAction;
    } else {
        actionCommand = key;
        a = getAction(key);
    }
    if (a != null) {
        b.setActionCommand(actionCommand);
        b.addActionListener(a);
        a.addPropertyChangeListener(new ActionChangedListener(b));
        b.setEnabled(a.isEnabled());
    } else {
        b.setEnabled(false);
    }

    String tip = guimap.getLabel(key + "Tip");
    if (tip != null) {
        b.setToolTipText(tip);
    }

    return b;
}