Java Swing How to - Change JButton Horizontal Text Position








Question

We would like to know how to change JButton Horizontal Text Position.

Answer

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
public class Main {
  public static void main(final String args[]) {
    JButton button = new JButton("Test");
/* w w w . j  a v a 2 s. c  o  m*/
    button.setHorizontalTextPosition(SwingConstants.LEFT);
    button.setIcon(new ImageIcon("r.gif"));
    button.setRolloverIcon(new ImageIcon("b.gif"));
    button.setRolloverEnabled(true);

    
    JOptionPane.showMessageDialog(null, button);
  }
}