Create a LineBorder in Java
Description
The following code shows how to create a LineBorder.
Example
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//from w w w.j a v a 2 s. com
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame {
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Some label text");
label.setBorder(BorderFactory.createLineBorder(Color.green));
label.setFont(new Font("Serif", Font.ITALIC, 16));
getContentPane().add(label);
pack();
setVisible(true);
}
public static void main(String arg[]) {
new Main();
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »