Is there a way to set the insets of a JFrame
?
I tried
frame.getContentPane().getInsets().set(10, 10, 10, 10);
and
frame.getInsets().set(10, 10, 10, 10);
but none of them seem to work.
Is there a way to set the insets of a JFrame
?
I tried
frame.getContentPane().getInsets().set(10, 10, 10, 10);
and
frame.getInsets().set(10, 10, 10, 10);
but none of them seem to work.
As this question does not have a definitive answer yet you can do it like basiljames said here. The correct way to do it would be to extend a
JFrame
and then override thegetInsets()
method.For example
You have to create an Object of LayOutConstraint and set its Insets. Like in below example I have used GridBagLayout() and used GridBagConstraint() object.
you can create a main
JPanel
and insert everything else into it.Then you can use
BorderFactory
to createEmptyBorder
orLineBorder
.see this answer: https://stackoverflow.com/a/17925693/8953378
Overriding the
Insets
ofJFrame
would not be the soultion to your actual problem. To answer your question, you cannot set the Insets ofJFrame
. You should extend JFrame and override thegetInsets
method to give the insets you require.So basically,
contentPanel
is the main container of your frame.