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
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.
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.
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.
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.
(Java docs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With