Empty Border : EmptyBorder « Swing « Java Tutorial






  1. The empty border leaves a transparent margin without any associated drawing.
  2. It's an alternative to using the insets in AWT.
  3. The class requires that fields such as top, left, bottom, and right be specified.
  4. You can also use an insets object to create an empty border.
Empty Border
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class EmptyBorderForLabel extends JFrame {

  public EmptyBorderForLabel() {
    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) {
    EmptyBorderForLabel s = new EmptyBorderForLabel();
    s.setVisible(true);
  }
}








14.105.EmptyBorder
14.105.1.Empty BorderEmpty Border
14.105.2.Creating Empty using its ConstructorCreating Empty using its Constructor
14.105.3.Adding EmptyBorder to a JButtonAdding EmptyBorder to a JButton
14.105.4.Creating and Setting an Empty Border from BorderFactory