AbstractButton: setHorizontalAlignment(int alignment)
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingConstants;
public class MainClass extends JFrame {
MainClass(String title) {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jb = new JButton("Ok", new ImageIcon("bullet.gif"));
jb.setHorizontalAlignment(SwingConstants.LEFT);
jb.setMnemonic('O');
getContentPane().add(jb, BorderLayout.CENTER);
jb = new JButton("<html><i>Cancel</i></html>");
jb.setVerticalAlignment(SwingConstants.BOTTOM);
jb.setDefaultCapable(true);
getContentPane().add(jb, BorderLayout.EAST);
getRootPane().setDefaultButton(jb);
setSize(200, 100);
setVisible(true);
}
public static void main(String[] args) {
new MainClass("Button Demo");
}
}
Related examples in the same category