Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Border Around JPanel

Reply
Thread Tools

Border Around JPanel

 
 
Jason Cavett
Guest
Posts: n/a
 
      06-26-2008
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.
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      06-26-2008
In article
<(E-Mail Removed)>,
Jason Cavett <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Jason Cavett
Guest
Posts: n/a
 
      06-27-2008
On Jun 26, 4:20*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
> *Jason Cavett <(E-Mail Removed)> 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;
}
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      06-27-2008
In article
<(E-Mail Removed)>,
Jason Cavett <(E-Mail Removed)> wrote:

> On Jun 26, 4:20*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > In article
> > <(E-Mail Removed)>,
> > *Jason Cavett <(E-Mail Removed)> 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
 
Reply With Quote
 
Jason Cavett
Guest
Posts: n/a
 
      06-30-2008
On Jun 27, 4:31*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
> *Jason Cavett <(E-Mail Removed)> wrote:
>
>
>
> > On Jun 26, 4:20*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > > In article
> > > <(E-Mail Removed)>,
> > > *Jason Cavett <(E-Mail Removed)> 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.
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      06-30-2008
In article
<(E-Mail Removed)>,
Jason Cavett <(E-Mail Removed)> wrote:

> On Jun 27, 4:31*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > In article
> > <(E-Mail Removed)>,
> > *Jason Cavett <(E-Mail Removed)> wrote:
> >
> >
> >
> > > On Jun 26, 4:20*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > > > In article
> > > > <(E-Mail Removed)>,
> > > > *Jason Cavett <(E-Mail Removed)> 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
 
Reply With Quote
 
Jason Cavett
Guest
Posts: n/a
 
      07-02-2008
On Jun 30, 3:56*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
> *Jason Cavett <(E-Mail Removed)> wrote:
>
>
>
> > On Jun 27, 4:31*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > > In article
> > > <(E-Mail Removed)>,
> > > *Jason Cavett <(E-Mail Removed)> wrote:

>
> > > > On Jun 26, 4:20*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > > > > In article
> > > > > <(E-Mail Removed)>,
> > > > > *Jason Cavett <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JPanel inside JPanel inside JFrame t1m1976 Java 1 11-07-2010 09:47 PM
[JPanel] Drop Down JPanel Raphael Jolivet Java 1 07-18-2008 12:30 AM
Jpanel Dashed Border? Barkster Java 16 07-03-2006 06:13 PM
Datagrid Border showing when I say no border tshad ASP .Net 0 01-31-2005 05:40 PM
Add a JPanel to a JPanel... Andreas Beresko Java 6 07-16-2004 12:10 AM



Advertisments