java 在 JPanels 上设置边框粗细?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29778456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:55:35  来源:igfitidea点击:

Set Border Thickness on JPanels?

javaswingjpanelborder

提问by NiallMitch14

I'm wondering if it is possible to adjust the thickness of a border around a JPanel in Java? I currently have a border defined and the JPanel adds the border around it but I would like it to be a little thicker:

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

Border border;
JPanel panel;

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

回答by Jean-Fran?ois Savard

I believe you could use BorderFactory

我相信你可以用 BorderFactory

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

See

回答by copeg

BorderFactory has a method that accepts two parameters - the Color and thickness

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

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

Alternatively, you can use the LineBorderclass to generate a thicker line border

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

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

回答by Muhammad Nasir Zafar

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

Note:Here border thickness is 3 and color is blue.

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