开发者

Is it possible to have a java swing border only on the top side?

开发者 https://www.devze.com 2022-12-18 11:26 出处:网络
I know how to create borders using BorderFactory but I don\'t see any开发者_开发知识库thing that lets me specify what sides I want the border on :SYou can use the MatteBorder to specify the dimensions

I know how to create borders using BorderFactory but I don't see any开发者_开发知识库thing that lets me specify what sides I want the border on :S


You can use the MatteBorder to specify the dimensions of the border in each side. The constructor of MatteBorder is:

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 panel = new JPanel();
panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, Color.BLACK));


From Sun tutorial:

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.

Is it possible to have a java swing border only on the top side?

(Java docs)


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.


text_field.setBorder( new MatteBorder(2, 0, 0, 0, Color.black));

The values can be varied accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消