如何删除 SwingX AutoCompleteDecorator?
我在 DefaultCellEditor 的 JTextField 上使用 SwingX AutoCompleteDecorator。但是,我在表的多列上使用相同的编辑器。自动完成建议在列之间必须有所不同,严格/非严格遵守也是如此。
到目前为止的代码是:
class MyEditor extends DefaultCellEditor {
public MyEditor() {
super(new JTextField());
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JTextField field = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
List<String> suggestions = this.getSuggestions(column, value);
if (column == 2) {
AutoCompleteDecorator.decorate(field, suggestions, true);
}
if (column == 3) {
AutoCompleteDecorator.decorate(field, suggestions, false);
}
return field;
}
似乎发生的情况是,第一次调用编辑器时,一切正常。在后续调用中(或者更确切地说,调用除第一次调用之外的任何其他列),例如,第 3 列的装饰器将添加到第 2 列的装饰器之上,这并没有多大作用。
关于该主题的 SwingX 文档相当稀疏。我发现装饰器似乎向文本字段添加了一个 FocusListener
。
有谁知道如何重置装饰器或至少找出应该删除哪个 FocusListener (调用装饰器后该字段上有三个)?
谢谢!
I am using a SwingX AutoCompleteDecorator on the JTextField of a DefaultCellEditor. However, I'm using the same Editor on multiple columns of the table. The auto-complete suggestions will have to differ between columns, as would the strict/non-strict adherence.
Code up to now is:
class MyEditor extends DefaultCellEditor {
public MyEditor() {
super(new JTextField());
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JTextField field = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
List<String> suggestions = this.getSuggestions(column, value);
if (column == 2) {
AutoCompleteDecorator.decorate(field, suggestions, true);
}
if (column == 3) {
AutoCompleteDecorator.decorate(field, suggestions, false);
}
return field;
}
What seems to happen is that the first time the Editor is called, everything works fine. On subsequent calls (or rather, calls on any other column than the first call), the decorator for, say, column 3 is added on top of the decorator for column 2, which doesn't do much good.
SwingX documentation is rather sparse on that topic. I have found out that the Decorator seems to add a FocusListener
to the textfield.
Does anyone know how to either reset the decorator or at least find out which FocusListener (there are three on the field after the decorator has been called) should be removed?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论