AbstractButton: setHorizontalAlignment(int alignment) : AbstractButton « javax.swing « Java by API






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

1.AbstractButton: addActionListener(ActionListener l)
2.AbstractButton: addChangeListener(ChangeListener l)
3.AbstractButton: addItemListener(ItemListener l)
4.AbstractButton: getActionCommand()
5.AbstractButton: setActionCommand(String actionCommand)
6.AbstractButton: setBackground(Color bg)
7.AbstractButton: setForeground(Color fg)
8.AbstractButton: setHorizontalTextPosition(int textPosition)
9.AbstractButton: setMnemonic(char mnemonic)