Setting insets for a contentPane?

S

Scott Steiner

Hi,

I want to add a JPanel that has a border to a JFrame. Here's what I did:

public class Test2 extends JFrame
{
...
public Test2()
{
...
Container con = this.getContentPane();
con.setLayout(new BorderLayout());

JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEtchedBorder());

con.add(pane);
...
}
}

All is fine but the border of the panel is far too close to the border
of the frame. Is there some way of setting insets for the contentpane? I
saw a getInsets() method for the frame and for the contentpane but I see
nothing that would allow me to set the insets.

Thanks!
 
T

Thomas Hawtin

Scott said:
All is fine but the border of the panel is far too close to the border
of the frame. Is there some way of setting insets for the contentpane? I
saw a getInsets() method for the frame and for the contentpane but I see
nothing that would allow me to set the insets.

I would suggest looking at javax.swing.border.CompoundBorder.

Tom Hawtin
 
V

Vova Reznik

Scott said:
Hi,

I want to add a JPanel that has a border to a JFrame. Here's what I did:

public class Test2 extends JFrame
{
...
public Test2()
{
...
Container con = this.getContentPane();
con.setLayout(new BorderLayout());

JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEtchedBorder());

con.add(pane);
...
}
}

All is fine but the border of the panel is far too close to the border
of the frame. Is there some way of setting insets for the contentpane? I
saw a getInsets() method for the frame and for the contentpane but I see
nothing that would allow me to set the insets.

Thanks!

javax.swing.border.AbstractBorder
public Insets getBorderInsets(Component c)
You can create your own Border (extending any Border you like) and
override that method and set that border to content pane.

Content pane of JFrame (not only) has BorderLayout by default
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top