Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2482 > unrolled thread

Setting component size wh

Started by"Chanchal" <chanchal@THRWHITE.remove-dii-this>
First post2011-04-27 15:39 +0000
Last post2011-04-27 15:39 +0000
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.gui


Contents

  Setting component size wh "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
    Re: Setting component siz "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
      Re: Setting component siz "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
        Re: Setting component siz "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
    Re: Setting component siz "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000

#2482 — Setting component size wh

From"Chanchal" <chanchal@THRWHITE.remove-dii-this>
Date2011-04-27 15:39 +0000
SubjectSetting component size wh
Message-ID<1190208435.321604.119210@g4g2000hsf.googlegroups.com>
  To: comp.lang.java.gui
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...

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2485 — Re: Setting component siz

From"Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this>
Date2011-04-27 15:39 +0000
SubjectRe: Setting component siz
Message-ID<fcrd7b$klf$1@south.jnrs.ja.net>
In reply to#2482
  To: comp.lang.java.gui
Chanchal wrote:

> 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...

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#gridbagConstraints>

-- 
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

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2488 — Re: Setting component siz

From"A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this>
Date2011-04-27 15:39 +0000
SubjectRe: Setting component siz
Message-ID<slrnff2g2j.1opa.aggedor@earl-grey.cloud9.net>
In reply to#2485
  To: comp.lang.java.gui
On 2007-09-19, Nigel Wade <nmw@ion.le.ac.uk> wrote:
> Chanchal wrote:
>
>> 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...
>
> 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#gridbagConstraints>
>

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

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2494 — Re: Setting component siz

From"Chanchal" <chanchal@THRWHITE.remove-dii-this>
Date2011-04-27 15:39 +0000
SubjectRe: Setting component siz
Message-ID<1190258214.945430.142950@w3g2000hsg.googlegroups.com>
In reply to#2488
  To: comp.lang.java.gui
On Sep 19, 11:29 am, "A. Bolmarcich" <agge...@earl-grey.cloud9.net>
wrote:
> On 2007-09-19, Nigel Wade <n...@ion.le.ac.uk> wrote:
>
>
>
>
>
> > Chanchal wrote:
>
> >> 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...
>
> > 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#g...>
>
> 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- Hide quoted text -
>
> - Show quoted text -

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

Regards

Chanchal

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2564 — Re: Setting component siz

From"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Date2011-04-27 15:39 +0000
SubjectRe: Setting component siz
Message-ID<e5eof35tnv03nrfh69p801ghao4s4msu5p@4ax.com>
In reply to#2482
  To: comp.lang.java.gui
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
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web