It's impossible. Instead, you will need to create a new class that inherits JTextField, and then will have the function validate() as private or protected , and call it every time you getText() (this means you will need @Override it) from him.
An alternative is to use Container.getComponent() and check for instanceof , and then check each field separately. However, this is contrary to what you are asking for.
source share