Add Icon to MatteBorder in Java
Description
The following code shows how to add Icon to MatteBorder.
Example
//from w ww . j av a 2s. co m
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 Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Sample Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Icon diamondIcon = new ImageIcon("a.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);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »