Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2007

Tip: Looking for answers? Try searching our database.

Setting component size while using border layout

Thread view: 
Chanchal - 19 Sep 2007 14:27 GMT
Hi,
 Is there any was we can mention size of component when we are using
border layout?Myproblem is that I have 3 JPanels placed side by side
on a JFrame with border layout. But i need the first and last JPanels
to occupy 25% each of the width and the middle one to occupy 50%. I'm
using Border Layout so that the JPanels will resize themselves when
the JFrame is resized.

Thanks in advance...
Tom N - 19 Sep 2007 14:43 GMT
>   Is there any was we can mention size of component when we are using
> border layout?Myproblem is that I have 3 JPanels placed side by side
> on a JFrame with border layout. But i need the first and last JPanels
> to occupy 25% each of the width and the middle one to occupy 50%. I'm
> using Border Layout so that the JPanels will resize themselves when
> the JFrame is resized.

You ought to use GridBagLayout.
Nigel Wade - 19 Sep 2007 15:54 GMT
> Hi,
>   Is there any was we can mention size of component when we are using
[quoted text clipped - 5 lines]
>
> Thanks in advance...

No. BorderLayout has a defined behaviour which doesn't match what you want. In
BorderLayout the outer components are all sized to their natural size (if
possible), and any extra space is only given to the CENTER component.

You should try GridBagLayout. Set the weightx (in GridBagConstraints) of the
left and right panels to 0.25, and to 0.5 for the centre panel.
<http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html#gridbagConst
raints
>

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

A. Bolmarcich - 19 Sep 2007 16:29 GMT
>> Hi,
>>   Is there any was we can mention size of component when we are using
[quoted text clipped - 13 lines]
> left and right panels to 0.25, and to 0.5 for the centre panel.
><http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html#gridbagConst
raints
>

GridBagLayout by itself does not do what the original poster wanted.

Depending on the preferred widths of the components and the amount of
extra space, the layout given by GridBagLayout may be close to the
desired one.  The layout will be the desired one if the preferred widths
of the components are in the same ratios as the weightx values or if the
preferred widths are zero.

It would be better to use a layout manager that does what is wanted, such
as TableLayout.
http://java.sun.com/products/jfc/tsc/articles/tablelayout/index.html
Chanchal - 20 Sep 2007 04:16 GMT
On Sep 19, 11:29 am, "A. Bolmarcich" <agge...@earl-grey.cloud9.net>
wrote:

> >> Hi,
> >>   Is there any was we can mention size of component when we are using
[quoted text clipped - 26 lines]
>
> - Show quoted text -

Thank you all for your suggestions. This has been really helpful

Regards

Chanchal
Roedy Green - 28 Sep 2007 00:14 GMT
On Wed, 19 Sep 2007 06:27:15 -0700, Chanchal
<chanchal.jacob@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>  Is there any was we can mention size of component when we are using
>border layout?

Here are three strategies.

1. try a different LayoutManger with direct tools to control what you
want.  See http://mindprod.com/jgloss/layout.html

2. fiddle with setMaximumSize, setMinimumSize, setPreferredSize.
see  http://mindprod.com/jgloss/getpreferredsize.html

3. Write your own LayoutManager that does what you want.  This is much
easier than you would think.  See
http://mindprod.com/jgloss/layout.html
http://mindprod.com/jgloss/layoutmanger.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.