What are the parameters that can be passed in setAlignment Function. Also what does this button1.setAlignment(1f) mean .
For Example
public class TwoButtons extends JFrame {
public TwoButtons() {
setTitle("Two Buttons");
JPanel basic = new JPanel();
basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
add(basic);
basic.add(Box.createVerticalGlue());
JPanel bottom = new JPanel();
bottom.setAlignmentX(1f);
bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
JButton ok = new JButton("OK");
JButton close = new JButton("Close");
bottom.add(ok);
bottom.add(Box.createRigidArea(new Dimension(5, 0)));
bottom.add(close);
bottom.add(Box.createRigidArea(new Dimension(15, 0)));
basic.add(bottom);
basic.add(Box.createRigidArea(new Dimension(0, 15)));
setSize(300, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
I think you are talking about setAlignmentX(1f) method. This method is defined in JComponent class. It sets the the vertical alignment.
http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/JComponent.html#setAlignmentX(float)
In your case it is “1f” so this component has (Component.RIGHT_ALIGNMENT) Right vertical alignment
Box.createRigidArea
Creates an invisible component that’s always the specified size.