- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to align JLabel text vertically top in Java?
Use the setVerticalAlignment() method to align JLabel text vertically to the top:
JLabel label = label.setVerticalAlignment(JLabel.TOP);
The following is an example to align JLabel text vertically to the top:
Example
import java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("This is demo label!"); label.setFont(new Font("Verdana", Font.PLAIN, 14)); label.setVerticalAlignment(JLabel.TOP); Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border); frame.add(label); frame.setSize(600,300); frame.setVisible(true); } }
Output
- Related Articles
- How to set the text of the JLabel to be right-justified and vertically centered in Java?
- How can we rotate a JLabel text in Java?
- How to left align components vertically using BoxLayout with Java?
- How to change text font for JLabel with HTML in Java?
- Java Program to set alignment for text in JLabel
- Java Program to change JLabel text after creation
- Vertically align numeric values in Java using Formatter
- How to create JLabel to hold multiline of text using HTML in Java?
- How to right align the text in a ComboBox in Java
- How can we implement a moving text using a JLabel in Java?
- How to change JLabel font in Java
- How to change JLabel size in Java?
- How to disable a JLabel in Java?
- How to add tooltip to JLabel in Java?
- How can I vertically align elements in a div?

Advertisements