Eddie Eddie - 3 months ago 8
Java Question

How to set the distance between line border and edge of window?

You know how when you do

panel.setBorder(BorderFactory.createTitledBorder(txt))

it creates a border, and if that's the only panel in your window, there will be
space between the border, and the edge of the window.

But if you do
panel2.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1))

the borer is gonna be touching the edge of a window.

QUESTION

How do you change the distance between a lineborder and the edge of a window

comment if not clear enough

Answer

the borer is gonna be touching the edge of a window....How do you change the distance between a lineborder and the edge of a window

You can nest borders using a CompoundBorder. For example, to create a 'padding' border around a line border:

CompoundBorder cb = new CompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createLineBorder(Color.BLACK));
myComponent.setBorder(cb);
Comments