Java-允许在具有L& F物质的可编辑JComboBox中使用退格键 [英] Java - Allow using backspace in an editable JComboBox with Substance L&F
问题描述
我正在使用物质L& F,并且已将JComboBox
设置为可编辑,以便可以从其弹出窗口中选择所需的值,或在其编辑器中键入一个新值.
I am using Substance L&F and I have set a JComboBox
to editable so that i can select the value that i want from its popup, or type a new value in its Editor.
键入一个新值可以很好地工作,但是如果我想从Combo编辑器中删除未键入的字母,然后单击Backspace即可,它会在编辑器中选择字母而不是擦除它们.这是屏幕截图:
Typing a new value works fine, but if i want to delete a miss-typed letter from the Combo editor, and i click Backspace to do that it selects the letters in the editor instead of erasing them. Here is a screenshot :
我希望Combo编辑器在键入键盘字母或Backspace或Delete时像JTextField一样工作,有没有办法做到这一点?或者是什么原因造成的?
I want the Combo editor to work like a JTextField when typing keyboard letters or Backspace or Delete in it, so is there a way to do that ? Or what is causing this?
推荐答案
关于以下内容的重要性,请参见下文 SSCCE 而不是发生错误的一切都是错误,大多数情况下,您的实际代码中存在错误,而没有 SSCCE ,我们就是不是明智的人.
See below for the importance of an SSCCE not everything that goes wrong is a bug, most of the times it something wrong in your actual code, which without an SSCCE we are non the wiser.
似乎对我来说很好:
启动时:
选择JComboBox
并按 Backspace 后:
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Test {
public Test() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JComboBox jc = new JComboBox(new String[]{"Hello", "Bye", "World", "Cruel"});
jc.setEditable(true);
frame.add(jc);
frame.pack();
frame.setVisible(true);
}
});
}
public static void main(String[] args) {
new Test();
}
}
更新
根据您的评论:
我认为这不会很好! ...这是物质上的问题; 我正在使用的L& F.
I did not think it would work fine ! ... It is a problem in Substance; the L&F i am using.
有关错误的详细信息,请参见下文:
See below for details on the Bug:
如上所述:
此行为是设计使然.这是物质的感觉"部分, 在可编辑的组合框上添加自动补全功能.
This behavior is by design. This is a "feel" part of Substance that adds auto-completion on editable comboboxes.
或者在此处中查看我的答案以了解更多信息L& F和/或制作自己的方式
Alternatively see my answer here for more L&Fs and/or a way to make your own
更新2 :
感谢@Brad(用于解密我从Substance:P链接的错误日志),可以轻松地解决此问题:
Thanks to @Brad (for deciphering the bug log I linked from Substance :P) to fix this simply do:
UIManager.put( LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE );
这篇关于Java-允许在具有L& F物质的可编辑JComboBox中使用退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!