【发布时间】:2014-08-24 23:58:37
【问题描述】:
我试图让 AutoCompleteSupport 在对象中搜索特定字符串,但是当我将 EventList 分配给 JComboBox 时,我不明白如何指示安装程序仅查询 Station 对象的“title”属性.相反,AutoCompleteSupport 会搜索整个对象名称字符串。我还需要实现另一件事,告诉 AutoCompleteSupport 只搜索特定对象中的这一组属性吗?
到目前为止的代码:
public class StationFinder extends JComboBox {
private EventList<Station> stations = new BasicEventList<Station>();
public StationFinder() {
setStations(); // this sets up the 'stations' property
SwingUtilities.invokeLater(new Runnable() {
public void run() {
AutoCompleteSupport.install(StationFinder.this, getStations());
}
});
}
}
这是 Station 对象:
public class Station {
private int id;
private String metaName;
private String title;
...
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getMetaName() {
return metaName;
}
public void setMetaName(String metaName) {
this.metaName = metaName;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
我尝试在 Station 对象中实现 FilterableText,但这根本不起作用。
【问题讨论】:
标签: java autocomplete jcombobox glazedlists