- 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
Create empty border with BorderFactory class in Java?
To create empty border, use the createEmptyBorder() method. Let us first create a label component −
JLabel label = new JLabel("Label with empty border!");
Now, create empty border with BorderFactory class −
label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
The following is an example to create empty border −
Example
package my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("Label with empty border!"); label.setFont(new Font("Verdana", Font.PLAIN, 16)); label.setVerticalAlignment(JLabel.BOTTOM); label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); frame.add(label); frame.setSize(550,350); frame.setVisible(true); } }
Output
Advertisements