Create a CompoundBorder and combine two line borders in Java
Description
The following code shows how to create a CompoundBorder and combine two line borders.
Example
/*from w ww . j a v a 2 s. com*/
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
public class Main extends JFrame {
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JLabel label;
label = new JLabel("Compound - red inside green lines");
label.setBorder(BorderFactory.createCompoundBorder(new LineBorder(
Color.green), new LineBorder(Color.red)));
panel.add(label);
getContentPane().add(panel);
pack();
}
public static void main(String[] args) {
Main s = new Main();
s.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »