I have an unusual situation that would most easily be solved by being able
to duplicate a JTextArea in size and position, then to swap between them by
making each visible at different times.
I know I can duplicate the JTextArea with clone() and I can get the size to
make sure they match. If I were working with an absolute layout, I know I
could position them both at the same place and switch between them by
making one visible while the other isn't. However, I'll be working with
other layouts types and I don't have access to the container the first one
is in.
Is there some fairly easy way I can duplicate the first JTextArea and swap
the two in and out without messing up other components or the display?
Thanks!
Hal
Daniel Pitts - 26 Feb 2008 20:45 GMT
> I have an unusual situation that would most easily be solved by being able
> to duplicate a JTextArea in size and position, then to swap between them by
[quoted text clipped - 13 lines]
>
> Hal
Look at java.awt.CardLayout

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Hal Vaughan - 26 Feb 2008 20:59 GMT
>> I have an unusual situation that would most easily be solved by being
>> able to duplicate a JTextArea in size and position, then to swap between
[quoted text clipped - 17 lines]
>>
> Look at java.awt.CardLayout
I was thinking that might work, but I was hoping for something easier. I
figure I'd have to remove the original component, put in a panel with the
CardLayout, then add both other components.
Hal
Daniel Pitts - 26 Feb 2008 21:46 GMT
>>> I have an unusual situation that would most easily be solved by being
>>> able to duplicate a JTextArea in size and position, then to swap between
[quoted text clipped - 23 lines]
>
> Hal
That is easy enough to do, isn't it? It is also the "correct" solution,
so messing with anything else could be trouble.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Roedy Green - 11 Mar 2008 02:35 GMT
>Is there some fairly easy way I can duplicate the first JTextArea and swap
>the two in and out without messing up other components or the display?
how about do the layout with one. do a getBounds on it and do a
setBounds on the invisible other. Then change the visibility and
trigger a repaint.
When it comes time to flip back, reverse the roles. You don't freeze
the layout with SetMinimum/Maxium/Preferred size to leave it free to
flex except when flipping.
I have flipped using setVisible(). JDisplay does this to flip between
the colour and B&W copy-pastable versions.
However, I have not tried the trick I described.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com