如何删除 SwingX AutoCompleteDecorator?

发布于 2024-12-12 03:30:47 字数 1008 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文