- 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 add a title to an existing line border in Java?
Here, we will see how to add a title to an existing Line border. Let’s say we have a label and the border is to be set −
LineBorder linedBorder = new LineBorder(Color.blue); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); JLabel label = new JLabel(); label.setBorder(titledBorder);
The following is an example to add a title to an existing line border −
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 linedBorder = new LineBorder(Color.blue); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); 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 add line border to JLabel in Java?
- How to add a JSON string to an existing JSON file in Java?
- How to add a title to JTable in Java Swing?
- How to add/append content to an existing file using Java?
- How to add border line below when value changes in an Excel column?
- How to add empty border to a JButton in Java?
- How to add empty border to JPanel in Java?
- How to create JFrame with no border and title bar in Java?
- How to add column to an existing table in PostgreSQL?
- How to add a border to an image with CSS?
- How to add columns to an existing MySQL table?
- How to add a chart title in Excel?
- How to add new value to an existing array in JavaScript?
- How to add current date to an existing MySQL table?
- How to add items/elements to an existing jagged array in C#?

Advertisements