- 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 create Titled Border for a component in Java?
To create a titled border for a component in Java, use the createTitledBorder() method. Let’s say we have a panel and we need to set a titled border to it. Here’s our panel −
JPanel panel = new JPanel();
Now, set the border and set the text for the tites border −
panel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "My Demo Table", TitledBorder.LEFT, TitledBorder.TOP));
The following is an example to create a titled border −
Example
package my; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "My Demo Table", TitledBorder.LEFT, TitledBorder.TOP)); String[][] rec = { { "001", "David", "AUS" }, { "002", "Steve", "AUS" }, { "003", "Yuvraj", "IND" }, { "004", "Kane", "NZ" }, { "005", "Ben", "ENG" }, { "006", "Eion", "ENG" }, { "007", "Miller", "SA" }, { "008", "Rohit", "IND" } }; String[] header = { "Id", "Player", "Team" }; JTable table = new JTable(rec, header); panel.add(new JScrollPane(table)); frame.add(panel); frame.setSize(550, 400); frame.setVisible(true); } }
Output
- Related Articles
- How to create titled border for a Panel in Java?
- How to create a compound border for a component in Java?
- How to create etched border for a component using BorderFactory class in Java?
- How to set the titled justification (position title text) of the titled border in Java
- Java Program to add Titled Border to Panel in Swing
- How to create two borders for a single component in Java?
- How to create a JMenuBar Component in Java?
- How to create Titled Pane using JavaFx?
- How to set vertical alignment for a component in Java?
- How to create a border with a raised beveled edge in Java?
- How to create a border with a lowered beveled edge in Java?
- How to create a Matte-look border using a solid color in Java?
- How to set border color for SoftBevelBorder in Java?
- How to create a collapsed border in HTML?
- How to create a Border, Border radius, and shadow to a UIView in iPhone/iOS?

Advertisements