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
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
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();
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
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 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:
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.
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!
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.