Adding EmptyBorder to a JButton : EmptyBorder « Swing « Java Tutorial






Adding EmptyBorder to a JButton
import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;

public class AnEmptyBorder {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Empty Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    Border emptyBorder = BorderFactory.createEmptyBorder(20, 20, 0, 0);
    JButton emptyButton = new JButton("With Empty");
    emptyButton.setBorder(emptyBorder);

    JButton nonemptyButton = new JButton("Without Empty");
    
    Container contentPane = frame.getContentPane();
    contentPane.add(emptyButton, BorderLayout.NORTH);
    contentPane.add(nonemptyButton, BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(300, frame.getHeight());
    frame.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