是否可以只在顶部有一个 java 摆动边框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2174319/
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
Is it possible to have a java swing border only on the top side?
提问by Becky
I know how to create borders using BorderFactory
but I don't see anything that lets me specify what sides I want the border on :S
我知道如何使用创建边框,BorderFactory
但我没有看到任何可以让我指定我想要边框的边的内容:S
采纳答案by Pool
From Sun tutorial:
来自Sun 教程:
The next picture shows some matte borders. When creating a matte border, you specify how many pixels it occupies at the top, left, bottom, and right of a component.
下图显示了一些磨砂边框。创建遮罩边框时,您可以指定它在组件的顶部、左侧、底部和右侧占据的像素数。
(Java 文档)
回答by Tom Hawtin - tackline
Matte and empty border allow you to specify the sizes on each side, which may be zero.
哑光和空边框允许您指定每边的大小,可能为零。
The Border
interface itself is quite easy to implement yourself if you want a custom look. I guess there may be third party libraries available containing styles not included within the Java library.
Border
如果您想要自定义外观,界面本身很容易实现。我猜可能有第三方库可用,其中包含 Java 库中未包含的样式。
回答by Alex Ntousias
You can use the MatteBorderto specify the dimensions of the border in each side. The constructor of MatteBorder
is:
您可以使用MatteBorder指定每边边框的尺寸。的构造函数MatteBorder
是:
public MatteBorder(int top,
int left,
int bottom,
int right,
Color matteColor)
So if you want to have a border only on the bottom and right sides of your JPanel
, you could write something like this:
所以如果你只想在你的底部和右侧有一个边框JPanel
,你可以写这样的东西:
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, Color.BLACK));
回答by salman pk
text_field.setBorder( new MatteBorder(2, 0, 0, 0, Color.black));
The values can be varied accordingly.
这些值可以相应地变化。