- 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
Java Program to set title position in Java
To set title position, use the setTitlePosition() method in Java. Let’s say we have to position the title above the border's top line. For that, use the constant ABOVE_TOP for the border −
setTitlePosition(TitledBorder.ABOVE_TOP);
The following is an example to set title position −
Example
package my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); LineBorder lineBorder = new LineBorder(Color.orange); TitledBorder titledBorder = BorderFactory.createTitledBorder(lineBorder, "Demo Title"); titledBorder.setTitlePosition(TitledBorder.ABOVE_TOP); JLabel label = new JLabel(); label.setBorder(titledBorder); Container contentPane = frame.getContentPane(); contentPane.add(label, BorderLayout.CENTER); frame.setSize(550, 300); frame.setVisible(true); } }
Output
- Related Articles
- How to set the titled justification (position title text) of the titled border in Java
- Java Program to set a spinner of dates in Java
- Java Program to set JTextArea to wrap by word in Java
- Java Program to set JComboBox in JOptionPane
- Program to convert Set to List in Java
- Program to convert Array to Set in Java
- How to Adjust Title Position in Matplotlib?
- Java Program to remove all elements from a set in Java
- Java Program to set the extent in JSlider
- Java Program to Split an Array from Specified Position
- Program to convert Set of Integer to Set of String in Java
- Program to convert set of String to set of Integer in Java
- Java Program to mark the current position in this input stream
- Java program to remove items from Set
- Java Program to Iterate over a Set

Advertisements