Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2008

Tip: Looking for answers? Try searching our database.

Duplicating and Swapping Out A Component

Thread view: 
Hal Vaughan - 26 Feb 2008 17:11 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.