PlainDocument: Name of the TextField which is using it?

Hi!

I have bind a JTextField to a Document (my own Documentclass extends DBPlainDokument)

Is it possible to get the fieldname (which is defined in an other class) in this Documentclass?

I need this, because in the method insertString I make an if command fpr every field. So I can define the inputdefinition for all fields in one Document.

Or is there a other posibillitiy ? I have 40 JTextField and I dont want to make an instance of the Documentclass for every TextField (40 instances?) There must be an other way. One Document instance for all fields, and in the Doc-class a method for every field.

What shall I do?

Wolfgang

[678 byte] By [kleindinst] at [2007-9-26 1:40:10]
# 1

Are you sure you want one document to be used for all 40 JTextFields? That would cause all of the JTextFields to contain the same data. Your design seems confused to me. You have designed a class with exactly 40 methods, expecting that there will be exactly 40 objects that refer to a single object of the class? And you want each of those 40 objects to somehow call a different one of those 40 methods? This is definitely a mess. But probably I have misunderstood your description?

DrClap at 2007-6-29 2:30:15 > top of Java-index,Archived Forums,Java Programming...
# 2

I have found a possibility to know in the document class what field will be changed now. (what field is calling the documentclass)

But you say it, I have an other problem. Every field contains the same data. No this is not was I want.

hh...

I am searching for a possibility to give a field some specifications. i.e. upperCase, only Digits, Digits and comma, Entry have to exist in a table of the database, and so on.

Every of the 40 JTextFields have other specifications.

I tried it with InputVerifier, with detailed programming, with Document. I have not found a satisfactory solution.

By using the Document, do I have to bind every Field to a own Document ? Do I have to write 40 Documetclasses ? (for every field one Document)

Were are the Database programmers ? How do you check Field entrys ?

Wolfgang

kleindinst at 2007-6-29 2:30:15 > top of Java-index,Archived Forums,Java Programming...
# 3

I have a solution now, so that not all fields contain the same text. I give every TextField an instance of the Document.

field1.setDocument(new KldDocument(this));

field2.setDocument(new KldDocument(this));

So I can use one Documentclass, and it is not nessecary to make a class for every field. In the Doc.class I write commandos for every field separat.

[code]

public void insertString(int offs, String str, AttributeSet a) throws BadLocationException

{ try

{

//##### field1 #######

if ( dev.field1.hasFocus() )

{ super.insertString(offs, str.toUpperCase(), a);

setMaxLength(4);

}

//####### field2 ########

if ( dev.field2.hasFocus() )

{ super.insertString(offs,str,a);

setMaxLength(30);

}

}

catch (BadLocationException e)

{ throw e;

}

}

kleindinst at 2007-6-29 2:30:15 > top of Java-index,Archived Forums,Java Programming...