Example usage for javax.swing JButton setHorizontalTextPosition

List of usage examples for javax.swing JButton setHorizontalTextPosition

Introduction

In this page you can find the example usage for javax.swing JButton 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(final String args[]) {
    JButton button = new JButton("Test");

    button.setHorizontalTextPosition(SwingConstants.LEFT);
    button.setIcon(new ImageIcon("r.gif"));
    button.setRolloverIcon(new ImageIcon("b.gif"));
    button.setRolloverEnabled(true);/*from  w ww .ja v  a 2s.  c o m*/

    JOptionPane.showMessageDialog(null, button);
}

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);/*w w  w.j a va  2  s.  c  o m*/
    frame.show();
}

From source file:SampleButton.java

public SampleButton() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    JButton b = new JButton("Test");
    b.setHorizontalTextPosition(SwingConstants.LEFT);
    b.setIcon(new ImageIcon("r.gif"));
    b.setRolloverIcon(new ImageIcon("b.gif"));
    b.setRolloverEnabled(true);/*from w  w  w . j  a  v a2  s . com*/

    b.setMnemonic('t');
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button pressed");
        }
    });
    p.add(b);
    getContentPane().add(p);
    pack();
}

From source file:ButtonwithImageIcon.java

public ButtonPanel() {

    JButton btn = new JButton("Push Me", new BoxIcon(Color.blue, 2));
    btn.setRolloverIcon(new BoxIcon(Color.cyan, 3));
    btn.setPressedIcon(new BoxIcon(Color.yellow, 4));

    btn.setHorizontalTextPosition(JButton.LEFT);
    btn.setBorder(BorderFactory.createEtchedBorder());
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button was pressed.");
        }/*from w w  w . ja v  a  2  s  . c  o  m*/
    });
    add(btn);
}

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;//from  www.  ja  v a2 s  .  c o  m
    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:com.simplexrepaginator.RepaginateFrame.java

protected JButton creatOutputButton() {
    JButton b = new JButton("Click or drag to set output file", PDF_1234);

    b.setHorizontalTextPosition(SwingConstants.LEFT);
    b.setIconTextGap(25);//from w ww  .ja  va 2  s. co m

    b.setTransferHandler(new OutputButtonTransferHandler());

    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            if (chooser.showOpenDialog(RepaginateFrame.this) != JFileChooser.APPROVE_OPTION)
                return;
            repaginator.setOutputFiles(Arrays.asList(chooser.getSelectedFiles()));
            output.setText("<html><center>" + StringUtils.join(repaginator.getOutputFiles(), "<br>"));
        }
    });

    return b;
}

From source file:com.simplexrepaginator.RepaginateFrame.java

protected JButton createInputButton() {
    JButton b = new JButton("Click or drag to set input files", PDF_1342);

    b.setHorizontalTextPosition(SwingConstants.RIGHT);
    b.setIconTextGap(25);/*w ww .j  a  va 2s  .  c  o m*/

    b.setTransferHandler(new InputButtonTransferHandler());

    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(true);
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            if (chooser.showOpenDialog(RepaginateFrame.this) != JFileChooser.APPROVE_OPTION)
                return;
            setInput(Arrays.asList(chooser.getSelectedFiles()));
            if (JOptionPane.showConfirmDialog(RepaginateFrame.this, "Use input paths as output paths?",
                    "Use Input As Output?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                setOutput(new ArrayList<File>(repaginator.getInputFiles()));
            }
        }
    });

    return b;
}

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  www  .jav  a2s .  com
        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:com.simplexrepaginator.RepaginateFrame.java

protected JButton createRepaginateButton() {
    JButton b = new JButton("<html><center>Click to<br>repaginate", REPAGINATE_ICON);

    b.setHorizontalTextPosition(SwingConstants.LEFT);
    b.setIconTextGap(25);/*from  w  w w.  ja v  a2 s .  c  om*/

    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                int[] documentsPages = repaginator.repaginate();
                JOptionPane.showMessageDialog(RepaginateFrame.this,
                        "Repaginated " + documentsPages[0] + " documents with " + documentsPages[1] + " pages.",
                        "Repagination Complete", JOptionPane.INFORMATION_MESSAGE);
            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(RepaginateFrame.this, ex.toString(), "Error During Repagination",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    return b;
}