aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to get a liquid layout? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get a liquid layout?" Watch "How to get a liquid layout?" New topic
Author

How to get a liquid layout?

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
nowadays most web pages are liquid, i mean, when resized they display gracefully
in my case i would like this textarea to extend itself as one resizes the window horizontally
i would apreciate any advice on how to achieve this (like the first case in the code bellow), though i only need horizontal elasticity
when i run the second case the textarea doesnt follow the resizing of the frame

if you uncomment each block and then try to resize the window you'll see my idea


java amateur
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you really need to understand the various layout managers (already pointed out to you in recent posts)

when you do this
JPanel panel = (JPanel)frame.getContentPane();

the panel becomes the contentPane, and contentPane's have a default of BorderLayout.
A single component added to that contentPane like this
panel.add(scroll);
will be added to the default, BorderLayout.CENTER
which means, in the absence of other BorderLayout constraints being used/taken,
'scroll' will take up 'all' of the available space

now, when you do this
JPanel panel = new JPanel();
...
...
frame.getContentPane().add(panel);

panel's default layoutManager is FlowLayout, and, as it is not now the contentPane,
the panel will take up all the available space, leaving the child component(scroll) at
its preferredSize
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Michael Dunn wrote:you really need to understand the various layout managers (already pointed out to you in recent posts)

believe me i'm doing my best
anyway thank you for your very clear explanation

when first reading the tutorials i entirely missed the point:

If the window is enlarged, the center area gets as much of the available space as possible

at first this was quite confusing because both layouts grab all the available space
in each case who gets all the space? the panel or the child?
but your answer cleared things

now i think i'm done with BorderLayout

still, i dont see a way of stopping the textArea growing in height along with resizing - i wanted it with a fixed height
should i search among other layout managers? i played a lot with sizes, but with no results

an off-topic note: i posed you two questions in the other topic (the challenge of helping someone else) and i'm quite curious about your answers
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
still, i dont see a way of stopping the textArea growing in height along with resizing


Then you haven't downloaded and executed the demo that comes with the tutorial.

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Rob Camick wrote:
still, i dont see a way of stopping the textArea growing in height along with resizing


Then you haven't downloaded and executed the demo that comes with the tutorial.


if you refer to the first one that is here, yes, i did
Button2(CENTER) is elastic either in vertical or horizontal

unless you mean disposing of bottom label and instead placing the scroll there:
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
You can play around with nesting of multiple panels depending on exactly what you are looking for:



or maybe:



Maybe in this case the GridBagLayout (although much more complicated to use in general) will be easier because it has a "fill" constraint which would allow you to stretch the text area vertically to match the height of the buttons. But don't ask me how to do this because I find GBL too confusing.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
and you say you'rnt a mind reader: i was just playing around like you just suggested
anyway second suggestion looks much better then the former

as to GBL i studied an example from Agile Java book, and it demonstrated GBL is a very complete and powerful layout manager, though quite intrincate (hope i'll never need it)

thanks for helping!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> an off-topic note: i posed you two questions in the other topic (the challenge of helping someone else) and i'm quite curious about your answers

1) looks like your posted solution should work, given the poster's stated problem,
but, in the absence of the original poster supplying a compilable problematic example,
it's hard to be sure whether it will help him/her or not - perhaps if he/she posted a response, we'd all know.

2) I used to post to the sun forums, but haven't done so for several months.
I post infrequently here (now), too many cross-posters who have little or no
regard for my time, so I have little regard for their problem, but every now and then
something interesting is posted.
 
 
subject: How to get a liquid layout?