// This label will appear left-justified and centered.
JLabel label = new JLabel(“My Label”);
// This label will appear centered both vertically and horizonally.
JLabel label2 = new JLabel(“My Label”, JLabel.CENTER);
// This label will appear right-justified and centered
JLabel label3 = new JLabel(“My Label”, JLabel.RIGHT);
/**
* The alignment can also be set to TOP or BOTTOM.
*/
// This label is aligned on the top and right-justified.
JLabel label4 = new JLabel(“My Label”, JLabel.RIGHT);
Label4.setVerticalAlignment(JLabel.TOP);
// This label is aligned on the top and left-justified.
JLabel label5 = new JLabel(“My Label”, JLabel.LEFT);
Label5.setVerticalAlignment(JLabel.TOP);
// This label is aligned on the bottom and right-justified.
JLabel label6 = new JLabel(“My Label”, JLabel.RIGHT);
Label6.setVerticalAlignment(JLabel.BOTTOM);
// This label is aligned on the bottom and left-justified.
JLabel label7 = new JLabel(“My Label”, JLabel.LEFT); Label7.setVerticalAlignment(JLabel.BOTTOM);
|