• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get a liquid layout?

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic