自动完成装饰覆盖
在我当前的项目中,我使用 SwingX 的 AutoCompleteDecorate
。 AutoCompleteDecorator.decorate(jComboBox1);
但是,我想覆盖退格操作。最初,使用 AutoCompleteDecorate
.decorate(JComboBox
) 时,按退格键会将组合框中的选择内容向左移动,并且不会删除前一个字符。我想实现默认的退格功能(即删除前一个字符),即使我 AutoCompleteDecorate
我的 JComboBox
也是如此。
请帮我解决我的问题。先感谢您。
In my current project, I am using AutoCompleteDecorate
from SwingX.AutoCompleteDecorator.decorate(jComboBox1);
However, I want to override the backspace action. Originally, using AutoCompleteDecorate
.decorate(JComboBox
), pressing backspace move the selection in combobox to the left and doesn't delete the previous character. I want to implement the default function of backspace (which is to delete previous character) even if I AutoCompleteDecorate
my JComboBox
.
Please help me solve my problem. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并非微不足道 - 装饰器在实现选择而不是删除方面走了很长的路;-)
首先,您需要定义您想要的行为。然后实现一个按照您的意图执行的操作并将其放置在编辑器的 ActionMap 中:
这是模糊的,因为我不知道您到底想要什么,最好查看 AutoComplete 的源代码以了解如何实现 myBackspace
<强>编辑
只是为了详细说明一下模糊性:我的第一个想法是简单地重新安装默认的退格键绑定,例如:
这很可能不是预期的:假设插入符位于包含的中间的某个位置中的元素可编辑组合,然后选择从插入符号到末尾的文本,因此 deletePrev 删除所选字符而不是上一个字符。这可能会导致实现自定义操作的方式:首先清除选择,然后删除Prev,然后检查新单词是否在列表中并重新选择(或不在)。不知道要求就很难说。
Not trivial - the decorator goes a long way to implement the select-instead-of-delete ;-)
First you need to define which behaviour you want. Then implement a Action that does as you intend and place it in the editor's ActionMap:
This is vague because because I can't know what exactly you want, best to look at the source of AutoComplete to get an idea of how to implement myBackspace
Edit
Just to elaborate a bit on the vagueness: my first thought was to simply re-install the default backspace binding like:
that's most probably not what is expected: assuming the caret is somewhere in the middle of a contained element in an editable combo, then the text from the caret to the end is selected, consequently the deletePrev deletes the selected not the prev char. Which might lead the way to implement the custom action: first clear the selection, then deletePrev, then check if the new word is in the list and re-select (or not). Hard to tell without knowing the requirement.