PlainDocument

How to find the text fields name in Document class ?am using two or more text field and all of them using PlainDocumentHow i cam find which textfield is currently am typingeach text field r used for different purpouseThanks & Regardsvipin
[284 byte] By [vipindas_mna] at [2007-10-3 3:41:47]
# 1

> How to find the text fields name in Document class ?

You can't. A Document can be shared between multiple JTextFields. So there is no one to one mapping.

If you think you need the name of the text field, then you are approaching your problem incorrectly. If you state what you are actually trying to do we can probably provide an alternate solution.

camickra at 2007-7-14 21:37:39 > top of Java-index,Desktop,Core GUI APIs...
# 2
im trying to find which text field is currently in use(typing)in each key event some methods r calling with out using key listenersIs it possible to find the active text fieldVipin
vipindas_mna at 2007-7-14 21:37:39 > top of Java-index,Desktop,Core GUI APIs...
# 3

> im trying to find which text field is currently in use(typing)

Why do you care? Are you doing some custom editing to make sure the data is valid. You should not be using a KeyListener to validate text as it is entered. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html]Using Text Fields[/url]. It shows you different ways to validate the data, The "Text Component Features" link shows how to use a DocumentFilter.

camickra at 2007-7-14 21:37:39 > top of Java-index,Desktop,Core GUI APIs...
# 4

actually my need is

when am typing in to text field the text will be get and .to use this data select some data on data base and it will be display on a table

for example iam typing 'A" the data start with a will be display on table

it is working properly

But the problem is am using two or more text and and inner class extended by palinDocument .the result on the table will be depends up on the which text field is currently am using

How i cam find which text field is currently am using with out using any listeners

vipindas_mna at 2007-7-14 21:37:39 > top of Java-index,Desktop,Core GUI APIs...
# 5
You should be using a DocumentListener. It will notify you whenever the text in a Document is changed. You then add a different DocumentLister to each Document. That way each DocumentListener has code specifically related to the change in that Document.
camickra at 2007-7-14 21:37:39 > top of Java-index,Desktop,Core GUI APIs...
# 6

To determine which text field had focus, you could add the same focus listener

to each field which simply sets a variable in the focusGained method to the

source of the event.

You could also create your own TextAction subclass and provide a method

which simply returns the last focused text component. Of course, if you have

text components other than the ones you're dealing with here, they could be

returned as well.

JayDSa at 2007-7-14 21:37:39 > top of Java-index,Desktop,Core GUI APIs...