Create a MatteBorder from BorderFactory in Java
Description
The following code shows how to create a MatteBorder from BorderFactory.
Example
//from w ww . j a v a2s . c o m
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.MatteBorder;
public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Sample Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Icon icon = new ImageIcon("a.gif");
MatteBorder matteBorder = (MatteBorder)BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);
JLabel aLabel = new JLabel("Bevel");
aLabel.setBorder(matteBorder);
aLabel.setHorizontalAlignment(JLabel.CENTER);
frame.add(aLabel);
frame.setSize(400, 200);
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »