I am wanting to reference an object of type JTextField and convert it to JFormattedTextField. Is it possible to convert to a subclass? I tried coding something to the affect of

ClassA.object = new JFormattedTextField();
ClassA.object.setValue(new Integer(number));

But no success. Any suggestions?

Edited by cac186: n/a

6 Years
Discussion Span
Last Post by NormR1

Object is declared as type JTextField in another class. The second line is giving me an error. It won't let me apply the setValue method. Even though I tried to declare it a JFormattedTextField it only wants to apply the methods of JTextField to the object. I would think this means that it is still somehow of the type JTextField??? Is it not declared correctly? I would post more code but I really don't have any.


it only wants to apply the methods of JTextField to the object

That's always been true. object is a specific type and the compiler will only recognize/find that methods that belong to that type.
Try casting object to be the type that it points/refers to.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.