The setVerticalTextPosition() method of the javax.swing.JLabel class sets the position of the text within the label along the vertical axis. It takes an integer argument which can have the following values:
- JLabel.TOP: the text is positioned at the top of the label - JLabel.CENTER: the text is centered within the label - JLabel.BOTTOM: the text is positioned at the bottom of the label
Code Examples:
Example 1: Setting the Text at the Top of the Label
JLabel label = new JLabel("Hello World"); label.setVerticalTextPosition(JLabel.TOP);
This code creates a new JLabel object with the text "Hello World" and sets its vertical text position to the top.
Example 2: Centering the Text in the Label
JLabel label = new JLabel("Hello World"); label.setVerticalTextPosition(JLabel.CENTER);
This code creates a new JLabel object with the text "Hello World" and centers the text vertically within the label.
Package Library:
The setVerticalTextPosition() method belongs to the javax.swing package which is a part of the Java Swing library. The Java Swing library provides a set of GUI components that can be used to build desktop applications in Java.
Java JLabel.setVerticalTextPosition - 30 examples found. These are the top rated real world Java examples of javax.swing.JLabel.setVerticalTextPosition extracted from open source projects. You can rate examples to help us improve the quality of examples.