Create a LineBorder from BorderFactory in Java
Description
The following code shows how to create a LineBorder from BorderFactory.
Example
/*from w w w .j av a2s . c om*/
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;
public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Line Borders");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LineBorder lineBorder = (LineBorder)BorderFactory.createLineBorder(Color.black);
JLabel component = new JLabel("label");
component.setBorder(lineBorder);
frame.add(component);
frame.pack();
frame.setSize(300, frame.getHeight());
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »