Border Around JPanel

Discussion in 'Java' started by Jason Cavett, Jun 26, 2008.

  1. Jason Cavett

    Jason Cavett Guest

    I have created a JPanel that uses a FlowLayout to hold a series of
    buttons. However, the height of the JPanel is too tall. It's not as
    simple as setting the dimensions or anything like that. Essentially,
    I want to remove the "border" (or the buffer) that surrounds the edges
    of the JPanel to bring the edges as close as possible to the edges of
    the buttons but without touching.

    If I do just try to set the JPanel's dimensions, the distance between
    the top of the buttons is farther away than the distance between the
    bottom.

    Is this possible to do? Thanks.
     
    Jason Cavett, Jun 26, 2008
    #1
    1. Advertising

  2. In article
    <>,
    Jason Cavett <> wrote:

    > I have created a JPanel that uses a FlowLayout to hold a series of
    > buttons. However, the height of the JPanel is too tall. It's not as
    > simple as setting the dimensions or anything like that. Essentially,
    > I want to remove the "border" (or the buffer) that surrounds the edges
    > of the JPanel to bring the edges as close as possible to the edges of
    > the buttons but without touching.
    >
    > If I do just try to set the JPanel's dimensions, the distance between
    > the top of the buttons is farther away than the distance between the
    > bottom.
    >
    > Is this possible to do? Thanks.


    Without code it's hard to say. JPanel defaults to FlowLayout, but an
    errant BorderLayout can add unexpected height. Adding a matte from
    BorderFactory in a contrasting color may help show where the problem
    originates. Alternatively, switch to BoxLayout.

    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, Jun 26, 2008
    #2
    1. Advertising

  3. Jason Cavett

    Jason Cavett Guest

    On Jun 26, 4:20 pm, "John B. Matthews" <> wrote:
    > In article
    > <>,
    >  Jason Cavett <> wrote:
    >
    > > I have created a JPanel that uses a FlowLayout to hold a series of
    > > buttons.  However, the height of the JPanel is too tall.  It's not as
    > > simple as setting the dimensions or anything like that.  Essentially,
    > > I want to remove the "border" (or the buffer) that surrounds the edges
    > > of the JPanel to bring the edges as close as possible to the edges of
    > > the buttons but without touching.

    >
    > > If I do just try to set the JPanel's dimensions, the distance between
    > > the top of the buttons is farther away than the distance between the
    > > bottom.

    >
    > > Is this possible to do?  Thanks.

    >
    > Without code it's hard to say. JPanel defaults to FlowLayout, but an
    > errant BorderLayout can add unexpected height. Adding a matte from
    > BorderFactory in a contrasting color may help show where the problem
    > originates. Alternatively, switch to BoxLayout.
    >
    > --
    > John B. Matthews
    > trashgod at gmail dot com
    > home dot woh dot rr dot com slash jbmatthews


    Here is the code.

    /**
    * The tree button panel sits above the project tree and provides
    various
    * buttons that perform different functions on the tree.
    *
    * @return javax.swing.JPanel
    */
    private JPanel getTreeButtonPanel() {
    if (treeButtonPanel == null) {
    treeButtonPanel = new JPanel();
    FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
    treeButtonPanel.setLayout(layout);

    treeButtonPanel.add(this.getExpandAllButton());
    treeButtonPanel.add(this.getCollapseAllButton());
    treeButtonPanel.add(this.getSortTreeButton());
    }

    return treeButtonPanel;
    }
     
    Jason Cavett, Jun 27, 2008
    #3
  4. In article
    <>,
    Jason Cavett <> wrote:

    > On Jun 26, 4:20 pm, "John B. Matthews" <> wrote:
    > > In article
    > > <>,
    > >  Jason Cavett <> wrote:
    > >
    > > > I have created a JPanel that uses a FlowLayout to hold a series of
    > > > buttons.  However, the height of the JPanel is too tall.  It's not as
    > > > simple as setting the dimensions or anything like that.  Essentially,
    > > > I want to remove the "border" (or the buffer) that surrounds the edges
    > > > of the JPanel to bring the edges as close as possible to the edges of
    > > > the buttons but without touching.

    > >
    > > > If I do just try to set the JPanel's dimensions, the distance between
    > > > the top of the buttons is farther away than the distance between the
    > > > bottom.

    > >
    > > > Is this possible to do?  Thanks.

    > >
    > > Without code it's hard to say. JPanel defaults to FlowLayout, but an
    > > errant BorderLayout can add unexpected height. Adding a matte from
    > > BorderFactory in a contrasting color may help show where the problem
    > > originates. Alternatively, switch to BoxLayout.


    What results did you get from these suggestions?

    > Here is the [meaningless code fragment].


    A Short, Self-Contained, Correct/Compilable Example would be more
    instructive: <http://pscode.org/sscce.html>.

    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, Jun 27, 2008
    #4
  5. Jason Cavett

    Jason Cavett Guest

    On Jun 27, 4:31 pm, "John B. Matthews" <> wrote:
    > In article
    > <>,
    >  Jason Cavett <> wrote:
    >
    >
    >
    > > On Jun 26, 4:20 pm, "John B. Matthews" <> wrote:
    > > > In article
    > > > <>,
    > > >  Jason Cavett <> wrote:

    >
    > > > > I have created a JPanel that uses a FlowLayout to hold a series of
    > > > > buttons.  However, the height of the JPanel is too tall.  It's not as
    > > > > simple as setting the dimensions or anything like that.  Essentially,
    > > > > I want to remove the "border" (or the buffer) that surrounds the edges
    > > > > of the JPanel to bring the edges as close as possible to the edges of
    > > > > the buttons but without touching.

    >
    > > > > If I do just try to set the JPanel's dimensions, the distance between
    > > > > the top of the buttons is farther away than the distance between the
    > > > > bottom.

    >
    > > > > Is this possible to do?  Thanks.

    >
    > > > Without code it's hard to say. JPanel defaults to FlowLayout, but an
    > > > errant BorderLayout can add unexpected height. Adding a matte from
    > > > BorderFactory in a contrasting color may help show where the problem
    > > > originates. Alternatively, switch to BoxLayout.

    >
    > What results did you get from these suggestions?
    >
    > > Here is the [meaningless code fragment].

    >
    > A Short, Self-Contained, Correct/Compilable Example would be more
    > instructive: <http://pscode.org/sscce.html>.
    >
    > --
    > John B. Matthews
    > trashgod at gmail dot com
    > home dot woh dot rr dot com slash jbmatthews


    I didn't get any results from your suggestions as I am not using a
    BorderLayout (which is what the code was trying to show). I'm just
    using a single panel with a FlowLayout and throwing some various
    things on it.

    Thanks anyway.
     
    Jason Cavett, Jun 30, 2008
    #5
  6. In article
    <>,
    Jason Cavett <> wrote:

    > On Jun 27, 4:31 pm, "John B. Matthews" <> wrote:
    > > In article
    > > <>,
    > >  Jason Cavett <> wrote:
    > >
    > >
    > >
    > > > On Jun 26, 4:20 pm, "John B. Matthews" <> wrote:
    > > > > In article
    > > > > <>,
    > > > >  Jason Cavett <> wrote:

    > >
    > > > > > I have created a JPanel that uses a FlowLayout to hold a series of
    > > > > > buttons.  However, the height of the JPanel is too tall.  It's not as
    > > > > > simple as setting the dimensions or anything like that.  Essentially,
    > > > > > I want to remove the "border" (or the buffer) that surrounds the edges
    > > > > > of the JPanel to bring the edges as close as possible to the edges of
    > > > > > the buttons but without touching.

    > >
    > > > > > If I do just try to set the JPanel's dimensions, the distance between
    > > > > > the top of the buttons is farther away than the distance between the
    > > > > > bottom.

    > >
    > > > > > Is this possible to do?  Thanks.

    > >
    > > > > Without code it's hard to say. JPanel defaults to FlowLayout, but an
    > > > > errant BorderLayout can add unexpected height. Adding a matte from
    > > > > BorderFactory in a contrasting color may help show where the problem
    > > > > originates. Alternatively, switch to BoxLayout.

    > >
    > > What results did you get from these suggestions?
    > >
    > > > Here is the [meaningless code fragment].

    > >
    > > A Short, Self-Contained, Correct/Compilable Example would be more
    > > instructive: <http://pscode.org/sscce.html>.

    >
    > I didn't get any results from your suggestions as I am not using a
    > BorderLayout (which is what the code was trying to show). I'm just
    > using a single panel with a FlowLayout and throwing some various
    > things on it.


    Ah, I see. Same with using colored borders? It looks like GridLayout
    gets JButtons pretty close to the edges, but there's some space, even
    with zero h/vgap. Setting the buttons' background color shows that the
    extra space belongs to the buttons.

    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, Jun 30, 2008
    #6
  7. Jason Cavett

    Jason Cavett Guest

    On Jun 30, 3:56 pm, "John B. Matthews" <> wrote:
    > In article
    > <>,
    >  Jason Cavett <> wrote:
    >
    >
    >
    > > On Jun 27, 4:31 pm, "John B. Matthews" <> wrote:
    > > > In article
    > > > <>,
    > > >  Jason Cavett <> wrote:

    >
    > > > > On Jun 26, 4:20 pm, "John B. Matthews" <> wrote:
    > > > > > In article
    > > > > > <>,
    > > > > >  Jason Cavett <> wrote:

    >
    > > > > > > I have created a JPanel that uses a FlowLayout to hold a series of
    > > > > > > buttons.  However, the height of the JPanel is too tall.  It's not as
    > > > > > > simple as setting the dimensions or anything like that.  Essentially,
    > > > > > > I want to remove the "border" (or the buffer) that surrounds the edges
    > > > > > > of the JPanel to bring the edges as close as possible to the edges of
    > > > > > > the buttons but without touching.

    >
    > > > > > > If I do just try to set the JPanel's dimensions, the distance between
    > > > > > > the top of the buttons is farther away than the distance between the
    > > > > > > bottom.

    >
    > > > > > > Is this possible to do?  Thanks.

    >
    > > > > > Without code it's hard to say. JPanel defaults to FlowLayout, but an
    > > > > > errant BorderLayout can add unexpected height. Adding a matte from
    > > > > > BorderFactory in a contrasting color may help show where the problem
    > > > > > originates. Alternatively, switch to BoxLayout.

    >
    > > > What results did you get from these suggestions?

    >
    > > > > Here is the [meaningless code fragment].

    >
    > > > A Short, Self-Contained, Correct/Compilable Example would be more
    > > > instructive: <http://pscode.org/sscce.html>.

    >
    > > I didn't get any results from your suggestions as I am not using a
    > > BorderLayout (which is what the code was trying to show).  I'm just
    > > using a single panel with a FlowLayout and throwing some various
    > > things on it.

    >
    > Ah, I see. Same with using colored borders? It looks like GridLayout
    > gets JButtons pretty close to the edges, but there's some space, even
    > with zero h/vgap. Setting the buttons' background color shows that the
    > extra space belongs to the buttons.
    >
    > --
    > John B. Matthews
    > trashgod at gmail dot com
    > home dot woh dot rr dot com slash jbmatthews


    Ahhh...okay. Well, I guess it doesn't matter too much. I'm somewhat
    picky about the GUIs I design, but it doesn't look too bad.

    Thanks for your help, John. Appreciate it.
     
    Jason Cavett, Jul 2, 2008
    #7
    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. tshad
    Replies:
    0
    Views:
    2,293
    tshad
    Jan 31, 2005
  2. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    27,120
  3. Barkster

    Jpanel Dashed Border?

    Barkster, Jun 27, 2006, in forum: Java
    Replies:
    16
    Views:
    6,268
    Barkster
    Jul 3, 2006
  4. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,603
    John B. Matthews
    Jul 18, 2008
  5. t1m1976
    Replies:
    1
    Views:
    2,500
    t1m1976
    Nov 7, 2010
Loading...

Share This Page