Create an empty border in Java
Description
The following code shows how to create an empty border.
Example
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
//from ww w .jav a 2 s. com
public class Main extends JFrame {
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JLabel label;
label = new JLabel("Empty");
label.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
panel.add(label);
getContentPane().add(panel);
pack();
}
public static void main(String[] args) {
Main s = new Main();
s.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »