Example usage for javax.swing AbstractButton setHorizontalTextPosition

List of usage examples for javax.swing AbstractButton setHorizontalTextPosition

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER",
        "SwingConstants.RIGHT", "SwingConstants.LEADING",
        "SwingConstants.TRAILING" }, description = "The horizontal position of the text relative to the icon.")
public void setHorizontalTextPosition(int textPosition) 

Source Link

Document

Sets the horizontal position of the text relative to the icon.

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setHorizontalTextPosition(20);
    jb.setIcon(new MyIcon());

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);/*from ww  w .  j a  va 2  s  .  com*/
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

/**
 * /*from  w  w w .j  av a 2s.c o m*/
 * TODO
 * @param action
 * @return
 */
public static AbstractButton createToolbarItem(Action action) {
    final AbstractButton button;
    if (action == null) {
        throw new NullPointerException("Action cannot be null!");
    } else if (action.getValue(Action.SELECTED_KEY) != null) {
        button = new JToggleButton(action);
    } else {
        button = new JButton(action);
    }

    button.setOpaque(false);
    // hide text if icon is available
    if (action != null
            && (action.getValue(Action.SMALL_ICON) != null || action.getValue(Action.LARGE_ICON_KEY) != null)) {
        button.setHideActionText(true);
    }
    button.setHorizontalTextPosition(JButton.CENTER);
    button.setVerticalTextPosition(JButton.BOTTOM);
    return button;
}

From source file:com.mightypocket.ashot.Mediator.java

private JToolBar createToolBar() {
    ApplicationActionMap actionMap = getActionMap();
    JToolBar bar = new JToolBar();
    bar.setRollover(true);/*from  w ww .  j ava 2 s. c  om*/
    toolBarMap.clear();
    final boolean hideText = !p.getBoolean(PREF_GUI_SHOW_TEXT_IN_TOOLBAR, true);
    for (String actionName : TOOLBAR) {
        if (TOOLBAR_SEPARATOR.equals(actionName)) {
            bar.addSeparator();
        } else {
            AbstractButton bt;
            if (actionName.startsWith(TOOLBAR_TOGGLE_BUTTON)) {
                actionName = StringUtils.substring(actionName, TOOLBAR_TOGGLE_BUTTON.length());
                bt = new JToggleButton(actionMap.get(actionName));
            } else {
                bt = new JButton(actionMap.get(actionName));
            }
            bt.setFocusable(false);
            bt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            bt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            bt.setHideActionText(hideText);
            bar.add(bt);
            toolBarMap.put(actionName, bt);
        }
    }

    return bar;
}

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.jav  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();
}