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


Groups > comp.lang.java.gui > #2488

Re: Setting component siz

From "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this>
Subject Re: Setting component siz
Message-ID <slrnff2g2j.1opa.aggedor@earl-grey.cloud9.net> (permalink)
Newsgroups comp.lang.java.gui
References <fcrd7b$klf$1@south.jnrs.ja.net>
Date 2011-04-27 15:39 +0000
Organization TDS.net

Show all headers | View raw


  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

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web