Example usage for javax.swing AbstractButton getPreferredSize

List of usage examples for javax.swing AbstractButton getPreferredSize

Introduction

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

Prototype

@Transient
public Dimension getPreferredSize() 

Source Link

Document

If the preferredSize has been set to a non-null value just returns it.

Usage

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 www.  j  a v  a 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();
}