开发者

Overwriting getText of JTextField

开发者 https://www.devze.com 2023-03-30 03:33 出处:网络
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. Wh

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

精彩评论

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

关注公众号