Using Icon to create border: MatteBorder : MatteBorder « Swing « Java Tutorial






Using Icon to create border: MatteBorder
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;

public class MatteBorderSample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon diamondIcon = new ImageIcon("yourImage.gif");
    Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon);

    
    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(matteBorder);
    aLabel.setHorizontalAlignment(JLabel.CENTER);

    frame.add(aLabel);
    frame.setSize(400, 200);
    frame.setVisible(true);
  }
}








14.107.MatteBorder
14.107.1.MatteBorder
14.107.2.Color MatteBorderColor MatteBorder
14.107.3.Using Icon to create border: MatteBorderUsing Icon to create border: MatteBorder
14.107.4.Creating and Setting a MatteBorder from BorderFactory