[英]Extend JFormattedTextField
I am extending a JFormattedTextField to add a listener. 我正在扩展JFormattedTextField以添加侦听器。 I have this working although it is probably not the best way to do it.
我有这项工作,尽管这可能不是最好的方法。 Is there not a way to use a single generic constructor?
有没有办法使用单个通用构造函数?
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());
}
});
}
}
It seems like there should be a way to use just one constructor with a generic format type as the first argument and for 'super'. 似乎应该有一种方法可以只使用一个具有通用格式类型的构造函数作为第一个参数,并用作“ super”。 TIA.
TIA。
就像JFormattedTextField构造函数一样,您可以使用Format
类型来捕获NumberFormat
类型和SimpleDateFormat
类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.