java JPanel 上的圆形边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6821789/
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-10-30 17:24:35  来源:igfitidea点击:

Rounded borders on a JPanel

javaswinguser-interfaceawtborder

提问by Doug

What I've got here is a JPanel with a rounded border that is set up as such:

我在这里得到的是一个带有圆形边框的 JPanel,其设置如下:

panel.setBorder(new LineBorder(PanelColor, 5, true));

The problem is, in each of the corners there are 2 diagonal opaque lines going from the outer corner to the inner corner that is the length of the border. Whatever is behind the border shows through. Is there any way to get rid of these lines and make the entire border one solid color? Thanks!

问题是,在每个角都有 2 条不透明的对角线,从外角到内角,即边界的长度。边界后面的任何东西都会显示出来。有什么办法可以去掉这些线条并使整个边框变成纯色?谢谢!

I'd attach a picture but I don't have enough rep to do so :P

我会附上一张图片,但我没有足够的代表来这样做:P

回答by mKorbel

Maybe hereis a way to paint RoundedLineBorder; please be careful with constants for nice output to the GUI.

也许是一种绘制 RoundedLineBorder 的方法;请注意常量,以便向 GUI 输出良好的内容。

回答by Grammin

Your problem may be that the background panel is white and your foreground panel is PanelColorand since you are rounding out the edges you are seeing the white background behind your foreground panel.

您的问题可能是背景面板是白色的,而您的前景面板是白色的,PanelColor并且由于您将边缘四舍五入,因此您会看到前景面板后面的白色背景。