开发者

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
    }  
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜