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 / General / May 2006

Tip: Looking for answers? Try searching our database.

Implementing DocumentListener with 2 JTextAreas

Thread view: 
Trung Chinh Nguyen - 16 May 2006 15:39 GMT
Hi,

I'm writing a program with 2 JTextAreas. When the text in 1 area changes
the text in the other needs to be updated as well. I'm using
DocumentListener to handle this. However when the text is updated the
DocumentEvent is fired as well. The only solution I can think of is
removing the DocumentListener before updating the text and adding it
after that, but that would be very inefficient. Please give me some
recommendations. Thank you very much.

Chinh
Thomas Hawtin - 16 May 2006 15:20 GMT
> I'm writing a program with 2 JTextAreas. When the text in 1 area changes
> the text in the other needs to be updated as well. I'm using
[quoted text clipped - 3 lines]
> after that, but that would be very inefficient. Please give me some
> recommendations. Thank you very much.

It's highly unlikely that adding or removing a listener will account for
a significant time for each key stroke. However, it's probably easier to
use a flag.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Trung Chinh Nguyen - 16 May 2006 22:26 GMT
> It's highly unlikely that adding or removing a listener will account for
> a significant time for each key stroke. However, it's probably easier to
> use a flag.

You're right. I was abusing Listeners way too much ><
Roedy Green - 21 May 2006 21:42 GMT
On Tue, 16 May 2006 14:39:24 GMT, Trung Chinh Nguyen
<chinhnt2k3@gmail.com> wrote, quoted or indirectly quoted someone who
said :

> The only solution I can think of is
>removing the DocumentListener before updating the text and adding it
>after that, but that would be very inefficient. Please give me some
>recommendations. Thank you very much.

I would leave the connection in place.  Just use  a boolean to tell
the handler when to do its thing.  You can flip that back and forth
with much less fuss than you can add and remove a listener. It
probably leaves far fewer dead objects lying in its wake too, but
don't quote me on that.  I would think the code would be simpler and
easier to follow.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



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.