Overwriting getText of JTextField
I wish to overwrite getText()
so that it can return a null value instead of a a blank value. I noticed that getText()
is a part of JTextComponent
and I've been unable to successfully overwrite it. What is the best w开发者_运维技巧ay to get the desired result?
You can subclass JTextField
and override the getText
method, as such
public final class JCustomTextField extends JTextField{
.
.
.
@Override
public String getText(){
// do stuff
}
}
Or you can inline the override, as such
JTextField textField = new JTextField(){
.
.
.
@Override
public String getText(){
// do stuff
}
};
精彩评论