Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

border

swing

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

like image 514
Becky Avatar asked Feb 01 '10 02:02

Becky


People also ask

How do you set a frame border in Java?

Yes you can draw the borders around the undecorated JFrame. Just simply get the root pane of the JFrame and set its borders by setBorder(Border border) method. As far as I know, this will only shrink down the root pane so it can draw the border inside the frame itself.

What is a matte border in Java?

public class MatteBorder extends EmptyBorder. A class which provides a matte-like border of either a solid color or a tiled icon. Warning: Serialized objects of this class will not be compatible with future Swing releases.

How do you remove a frame border in Java?

setPreferredSize(...) pack(); inside the JFrame constructor will adjust everything so that the titlebar and borders will not impact the view of the content pane. For anyone else that may need this, you have to set the preferred size of the content pane specifically as that is what you want to appear correctly.


2 Answers

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)); 
like image 68
Alex Ntousias Avatar answered Sep 22 '22 01:09

Alex Ntousias


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.

(Java docs)

like image 26
Pool Avatar answered Sep 19 '22 01:09

Pool