Setting insets for a contentPane?  
Author Message
Scott Steiner





PostPosted: 2005-7-19 23:56:00 Top

java-programmer, Setting insets for a contentPane? 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!
 
Thomas Hawtin





PostPosted: 2005-7-19 23:57:00 Top

java-programmer >> Setting insets for a contentPane? Scott Steiner wrote:
>
> 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
--
Unemployed English Java programmer
 
Vova Reznik





PostPosted: 2005-7-20 0:17:00 Top

java-programmer >> Setting insets for a contentPane? Scott Steiner wrote:
> 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