Setting insets for a contentPane?

Discussion in 'Java' started by Scott Steiner, Jul 19, 2005.

  1. 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!
    Scott Steiner, Jul 19, 2005
    #1
    1. Advertising

  2. 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
    Thomas Hawtin, Jul 19, 2005
    #2
    1. Advertising

  3. Scott Steiner

    Vova Reznik Guest

    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
    Vova Reznik, Jul 19, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Srinivasa Raghavan Sethuraman
    Replies:
    0
    Views:
    548
    Srinivasa Raghavan Sethuraman
    Jun 30, 2004
  2. Ike

    JButton Insets

    Ike, Aug 29, 2003, in forum: Java
    Replies:
    0
    Views:
    2,128
  3. apchar
    Replies:
    3
    Views:
    1,829
    Andrew Hobbs
    Feb 3, 2004
  4. Tom Parson
    Replies:
    4
    Views:
    737
    Knute Johnson
    Nov 15, 2005
  5. Allen
    Replies:
    0
    Views:
    649
    Allen
    Aug 14, 2006
Loading...

Share This Page