首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展JFormattedTextField

扩展JFormattedTextField
EN

Stack Overflow用户
提问于 2017-07-01 09:27:17
回答 1查看 101关注 0票数 0

我正在扩展一个JFormattedTextField以添加一个侦听器。我有这方面的工作,虽然这可能不是最好的方法。难道没有一种方法可以使用单一的通用构造函数吗?

代码语言:javascript
复制
public class TimeLineTextClass extends JFormattedTextField {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private TimelineRecord timeLine;

public TimeLineTextClass (NumberFormat tlformat_,HashMap<Integer,JComponent> fieldList_,int field_,TimelineRecord timeLine_) {
    super(tlformat_);
    timeLine=timeLine_;
    getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            // Ignore - Using plain document

        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            timeLine.setObject((String) getClientProperty("type"),getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            timeLine.setObject((String) getClientProperty("type"),getText());
        }

    });
}

public TimeLineTextClass (SimpleDateFormat tlformat_,HashMap<Integer,JComponent> fieldList_,int field_,TimelineRecord timeLine_) {
    super(tlformat_);
    timeLine=timeLine_;
    getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            // Ignore - Using plain document

        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            timeLine.setObject((String) getClientProperty("type"),(String) getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            timeLine.setObject((String) getClientProperty("type"),(String) getText());
        }

    });
}

}

似乎应该有一种方法只使用一个构造函数,其中包含一个泛型格式类型作为第一个参数,并用于“Super”。蒂娅。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-01 12:37:13

就像JFormattedTextField构造函数一样,您可以使用Format类型来捕获NumberFormat类型和SimpleDateFormat类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44859378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档