Creating a JLabel Component

// The text is left-justified and vertically centered JLabel label = new JLabel("Text Label"); // The text is horizontally and vertically centered label = new JLabel("Text Label", JLabel.CENTER); // The text is right-justified and vertically centered label = new JLabel("Text Label", JLabel.RIGHT); // The text is left-justified and top-aligned label = new JLabel("Text Label", JLabel.LEFT); label.setVerticalAlignment(JLabel.TOP); // The text is right-justified and top-aligned label = new JLabel("Text Label", JLabel.RIGHT); label.setVerticalAlignment(JLabel.TOP); // The text is left-justified and bottom-aligned label = new JLabel("Text Label", JLabel.LEFT); label.setVerticalAlignment(JLabel.BOTTOM); // The text is right-justified and bottom-aligned label = new JLabel("Text Label", JLabel.RIGHT); label.setVerticalAlignment(JLabel.BOTTOM);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.