在JPanels上设置边框厚度?

时间:2015-04-21 16:48:23

标签: java swing jpanel border

我想知道是否可以在Java中调整JPanel周围边框的厚度?我目前有一个边框定义,JPanel添加边框,但我希望它更厚一点:

Border border;
JPanel panel;

border = BorderFactory.creatLineBorder(Color.RED);
panel = new JPanel();
panel.setBorder(border);

3 个答案:

答案 0 :(得分:4)

我相信你可以使用BorderFactory

panel.setBorder(BorderFactory.createStrokeBorder(new BasicStroke(5.0f));

答案 1 :(得分:3)

BorderFactory有一个接受两个参数的方法 - 颜色和厚度

border = BorderFactory.creatLineBorder(Color.RED, thickness);

或者,您可以使用LineBorder类生成较粗的边框

LineBorder border = new LineBorder(Color.RED, thickness)
panel.setBorder(border);

答案 2 :(得分:2)

JPanel panel1=new JPanel();
 panel1.setBounds(0,0,201,201);
 panel1.setBorder(BorderFactory.createLineBorder(Color.BLUE,3));

注意:此处边框粗细为3,颜色为蓝色。