Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Document Listener for a set of JTextArea(s)

2 views
Skip to first unread message

Joseph Mueller

unread,
Mar 10, 2007, 10:57:02 PM3/10/07
to
I am developing an application that has a collection of JTextArea(s). I
want to detect text changes to any of them without identifying which one
was changed. Can I use a single Document listener for all the
JTextArea(s) or do I need a unique one for each area?

Paul Furbacher [TeamB]

unread,
Mar 11, 2007, 9:10:57 AM3/11/07
to
Joseph Mueller wrote:

Sounds like it would work. The interface to DocumentEvent,
the argument passed to you in the event message, gives
you access to the Document via getDocument(). That would
give you all the info you need, since you don't care about
which text area the document belongs to.

Give it a try with a small demo.


--


Paul Furbacher (TeamB)

Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.

Joe Mueller

unread,
Mar 12, 2007, 11:15:51 AM3/12/07
to
Paul Furbacher [TeamB] wrote:
> Joseph Mueller wrote:
>
>> I am developing an application that has a collection of JTextArea(s).
>> I want to detect text changes to any of them without identifying which
>> one was changed. Can I use a single Document listener for all the
>> JTextArea(s) or do I need a unique one for each area?
>
> Sounds like it would work. The interface to DocumentEvent,
> the argument passed to you in the event message, gives
> you access to the Document via getDocument(). That would
> give you all the info you need, since you don't care about
> which text area the document belongs to.
>
> Give it a try with a small demo.
>
>
Thanks for the information. My test case worked.
I did however have to code a

Document documentN = jTextAreaN.getDocument();

and a

documentN.addDocumentListener( new
Frame_1_Document_documentAdapter(this));

for each JTextArea.

Don't know if there are any more shortcuts.

Paul Furbacher [TeamB]

unread,
Mar 12, 2007, 11:49:26 AM3/12/07
to
Joe Mueller wrote:

> [...]


> Thanks for the information. My test case worked.
> I did however have to code a
>
> Document documentN = jTextAreaN.getDocument();
>
> and a
>
> documentN.addDocumentListener( new
> Frame_1_Document_documentAdapter(this));
>
> for each JTextArea.
>
> Don't know if there are any more shortcuts.

That sounds right except that you could point
them all at the same listener (maybe you did that).

The Property Inspector in the UI Designer doesn't
give you access so you have to manually code this.
Not a terribly big deal -- on the plus side, it
keeps your hand in the business of writing code
for such things as listeners. (Having the
Designer do everything can make a lot of essential,
underlying knowledge go poof after a while.)

Joe Mueller

unread,
Mar 12, 2007, 7:44:52 PM3/12/07
to
Paul Furbacher [TeamB] wrote:
> Joe Mueller wrote:
>
>> [...]
>> Thanks for the information. My test case worked.
>> I did however have to code a
>>
>> Document documentN = jTextAreaN.getDocument();
>>
>> and a
>>
>> documentN.addDocumentListener( new
>> Frame_1_Document_documentAdapter(this));
>>
>> for each JTextArea.
>>
>> Don't know if there are any more shortcuts.
>
> That sounds right except that you could point
> them all at the same listener (maybe you did that).
>
> The Property Inspector in the UI Designer doesn't
> give you access so you have to manually code this.
> Not a terribly big deal -- on the plus side, it
> keeps your hand in the business of writing code
> for such things as listeners. (Having the
> Designer do everything can make a lot of essential,
> underlying knowledge go poof after a while.)
>
>
Yes, I did point them all to the same listener. I agree that it is good
to keep your hand in coding. Nothing like repetion to make things sink
in, especially if your an old timer like me trying to learn a new
programming language.
0 new messages