Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTextField overriding

Status
Not open for further replies.

kohinoor2007

Programmer
Mar 21, 2007
69
DE

Hi guys,

Have a class ,which Iam extending from "JTextField" under swing.Want to overide the " setText" function as follows:
Want to set a flag before I call the super class "SetText".How could I achieve it....

public void setText(String text){

val = true; // "Val" is a boolean declared in the class.
super().setText(text); // this gives a compile time error.
val = false;
}


Have implemented a DocumentEvent which is fired each time characters are inserted or removed from a text component.

The event is also fired if the set of attributes in the text component is changed.That I want to avoid.Thats why Iam overriding the "setText".

How can I modify my overrided "setText" function the way I have described,so that I can call the super "setText" function...


Thanks in advance......
 
I think you need to drop the () after super.

Code:
super.setText(text);

 
super() is used for constructors. I think, still new to Java.
 
kdor is right. Does your example compile?

What you can do is adding a listener that will only throw the events if they come from a text change.

Cheers,
Dian
 
Thanks Kodr & Dianceht.

With super.setText(text); it worked.

Thank u guys....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top