package WindowsandApplet;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;
public class test20180506Border extends JFrame {
static JPanel showBowder(Border b) {
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
String nm = b.getClass().getName();
System.out.println(nm);
nm = nm.substring(nm.lastIndexOf('.') + 1);
jp.add(new JLabel(nm, JLabel.CENTER), BorderLayout.CENTER);
jp.setBorder(b);
return jp;
}
public test20180506Border() {
Container cp = getContentPane();
// 两行四列
cp.setLayout(new GridLayout(2, 4));
cp.add(showBowder(new TitledBorder("Title")));
cp.add(showBowder(new EtchedBorder()));
cp.add(showBowder(new LineBorder(Color.BLUE)));
// 四个数字参数分别是距离边框的距离上左下右.
cp.add(showBowder(new MatteBorder(5, 5, 30, 30, Color.green)));
// 边框形状为凸起
cp.add(showBowder(new BevelBorder(BevelBorder.RAISED)));
// 边框形状为凹陷。
cp.add(showBowder(new BevelBorder(BevelBorder.LOWERED)));
// 为两个边框组合的边框样式,第一个为外边框,第二个为内边框。
cp.add(showBowder(new CompoundBorder(new EtchedBorder(), new LineBorder(Color.red))));
}
public static void main(String[] args) {
Consoletest.run(new test20180506Border(), 500, 300);
}
}
JBorder
最新推荐文章于 2021-04-05 11:43:47 发布