Example usage for javax.swing JButton setVerticalTextPosition

List of usage examples for javax.swing JButton setVerticalTextPosition

Introduction

In this page you can find the example usage for javax.swing JButton setVerticalTextPosition.

Prototype

@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.TOP", "SwingConstants.CENTER",
        "SwingConstants.BOTTOM" }, description = "The vertical position of the text relative to the icon.")
public void setVerticalTextPosition(int textPosition) 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JButton button = new JButton();
    // Place text over center of icon; they both occupy the same space
    button.setVerticalTextPosition(SwingConstants.CENTER);
    button.setHorizontalTextPosition(SwingConstants.CENTER);

    // Place text above icon
    button.setVerticalTextPosition(SwingConstants.TOP);
    button.setHorizontalTextPosition(SwingConstants.CENTER);

    // Place text below icon
    button.setVerticalTextPosition(SwingConstants.BOTTOM);
    button.setHorizontalTextPosition(SwingConstants.CENTER);

    // Place text to the left of icon, vertically centered
    button.setVerticalTextPosition(SwingConstants.CENTER);
    button.setHorizontalTextPosition(SwingConstants.LEFT);

    // Place text to the left of icon and align their tops
    button.setVerticalTextPosition(SwingConstants.TOP);
    button.setHorizontalTextPosition(SwingConstants.LEFT);

    // Place text to the left of icon and align their bottoms
    button.setVerticalTextPosition(SwingConstants.BOTTOM);
    button.setHorizontalTextPosition(SwingConstants.LEFT);

    // Place text to the right of icon, vertically centered
    button.setVerticalTextPosition(SwingConstants.CENTER);
    button.setHorizontalTextPosition(SwingConstants.RIGHT);

    // Place text to the right of icon and align their tops
    button.setVerticalTextPosition(SwingConstants.TOP);
    button.setHorizontalTextPosition(SwingConstants.RIGHT);

    // Place text to the right of icon and align their bottoms
    button.setVerticalTextPosition(SwingConstants.BOTTOM);
    button.setHorizontalTextPosition(SwingConstants.RIGHT);

}

From source file:MovingIconTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    JButton b;
    Icon icon = new PieIcon(Color.red);
    b = new JButton("Default", icon);
    contentPane.add(b, BorderLayout.NORTH);
    b = new JButton("Text Left", icon);
    b.setHorizontalTextPosition(JButton.LEFT);
    contentPane.add(b, BorderLayout.SOUTH);
    b = new JButton("Text Up", icon);
    b.setHorizontalTextPosition(JButton.CENTER);
    b.setVerticalTextPosition(JButton.TOP);
    contentPane.add(b, BorderLayout.EAST);
    b = new JButton("Text Down", icon);
    b.setHorizontalTextPosition(JButton.CENTER);
    b.setVerticalTextPosition(JButton.BOTTOM);
    contentPane.add(b, BorderLayout.WEST);
    b = new JButton("Align Bottom Left", icon);
    b.setHorizontalAlignment(JButton.LEFT);
    b.setVerticalAlignment(JButton.BOTTOM);
    contentPane.add(b, BorderLayout.CENTER);
    frame.setSize(300, 200);//from  w  w w  .  ja  v  a  2 s  . c om
    frame.show();
}

From source file:BoxAlignmentDemo.java

protected JPanel createButtonRow(boolean changeAlignment) {
    JButton button1 = new JButton("A JButton", createImageIcon("images/middle.gif"));
    button1.setVerticalTextPosition(AbstractButton.BOTTOM);
    button1.setHorizontalTextPosition(AbstractButton.CENTER);

    JButton button2 = new JButton("Another JButton", createImageIcon("images/geek-cght.gif"));
    button2.setVerticalTextPosition(AbstractButton.BOTTOM);
    button2.setHorizontalTextPosition(AbstractButton.CENTER);

    String title;//  w  ww.  j  a v  a 2 s  .com
    if (changeAlignment) {
        title = "Desired";
        button1.setAlignmentY(BOTTOM_ALIGNMENT);
        button2.setAlignmentY(BOTTOM_ALIGNMENT);
    } else {
        title = "Default";
    }

    JPanel pane = new JPanel();
    pane.setBorder(BorderFactory.createTitledBorder(title));
    pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
    pane.add(button1);
    pane.add(button2);
    return pane;
}

From source file:eu.delving.sip.frames.AllFrames.java

public JComponent getSidePanel() {
    JPanel arrangements = new JPanel();
    arrangements.setLayout(new BoxLayout(arrangements, BoxLayout.Y_AXIS));
    for (Arrangement a : this.arrangements) {
        JButton b = new JButton(a);
        b.setHorizontalTextPosition(JButton.CENTER);
        b.setVerticalTextPosition(JButton.BOTTOM);
        b.setFont(new Font("Sans", Font.PLAIN, 10));
        arrangements.add(b);/*from  w  w w.  j av a2  s. c  om*/
        arrangements.add(Box.createVerticalStrut(5));
    }
    arrangements.add(Box.createVerticalGlue());
    JPanel p = new JPanel(new BorderLayout());
    p.add(arrangements, BorderLayout.CENTER);
    return scrollV(p);
}

From source file:org.apache.marmotta.splash.common.ui.SelectionDialog.java

public static int select(String title, String message, String description, List<Option> options,
        int defaultOption) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);/*from  w ww.  j  av a2s.c om*/
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final AtomicInteger result = new AtomicInteger(Math.max(defaultOption, -1));

    JButton defaultBtn = null;

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    // All the options
    cLabel.ipadx = 10;
    cLabel.ipady = 10;
    cLabel.insets = new Insets(5, 15, 0, 15);
    for (int i = 0; i < options.size(); i++) {
        cLabel.gridy++;

        final Option o = options.get(i);
        final JButton btn = new JButton(
                "<html>" + StringEscapeUtils.escapeHtml3(o.label).replaceAll("\\n", "<br>"),
                MessageDialog.loadIcon(o.icon));
        if (StringUtils.isNotBlank(o.info)) {
            btn.setToolTipText("<html>" + StringEscapeUtils.escapeHtml3(o.info).replaceAll("\\n", "<br>"));
        }

        btn.setHorizontalAlignment(AbstractButton.LEADING);
        btn.setVerticalTextPosition(AbstractButton.CENTER);
        btn.setHorizontalTextPosition(AbstractButton.TRAILING);

        final int myAnswer = i;
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                result.set(myAnswer);
                dialog.setVisible(false);
            }
        });

        root.add(btn, cLabel);
        if (i == defaultOption) {
            dialog.getRootPane().setDefaultButton(btn);
            defaultBtn = btn;
        }
    }

    final Icon icon = MessageDialog.loadIcon();
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2 + options.size();
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    final JButton close = new JButton("Cancel");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result.set(-1);
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2 + options.size();
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(15, 5, 5, 5);

    root.add(close, cClose);
    if (defaultOption < 0) {
        dialog.getRootPane().setDefaultButton(close);
        defaultBtn = close;
    }

    dialog.pack();
    dialog.setLocationRelativeTo(null);
    defaultBtn.requestFocusInWindow();

    dialog.setVisible(true);
    dialog.dispose();

    return result.get();
}

From source file:uk.chromis.pos.forms.JRootApp.java

private void listPeople() {
    try {/* w  ww  . jav  a2 s. c  om*/
        jScrollPane1.getViewport().setView(null);
        JFlowPanel jPeople = new JFlowPanel();
        jPeople.applyComponentOrientation(getComponentOrientation());
        java.util.List people = m_dlSystem.listPeopleVisible();

        for (int i = 0; i < people.size(); i++) {

            AppUser user = (AppUser) people.get(i);
            JButton btn = new JButton(new AppUserAction(user));
            btn.applyComponentOrientation(getComponentOrientation());
            btn.setFocusPainted(false);
            btn.setFocusable(false);
            btn.setRequestFocusEnabled(false);
            btn.setMaximumSize(new Dimension(130, 60));
            btn.setPreferredSize(new Dimension(130, 60));
            btn.setMinimumSize(new Dimension(130, 60));
            btn.setHorizontalAlignment(SwingConstants.CENTER);
            btn.setHorizontalTextPosition(AbstractButton.CENTER);
            btn.setVerticalTextPosition(AbstractButton.BOTTOM);
            jPeople.add(btn);
        }
        jScrollPane1.getViewport().setView(jPeople);

    } catch (BasicException ee) {
    }
}