- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Substance L&F,并且已将 JComboBox
设置为可编辑,以便我可以从其弹出窗口中选择所需的值,或在其编辑器中键入新值。
输入新值效果很好,但如果我想从组合编辑器中删除误输入的字母,并且我单击退格键来执行此操作,它会选择编辑器中的字母而不是删除它们。这是屏幕截图:
我希望组合编辑器在输入键盘字母或 Backspace 或 Delete 时像 JTextField 一样工作,那么有没有办法做到这一点?或者是什么原因造成的?
最佳答案
请参阅下文了解 SSCCE 的重要性并非所有出错的事情都是错误,大多数时候它是您的实际代码中的错误,没有 SSCCE我们并不聪明。
似乎对我来说效果很好:
启动时:
选择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();
}
}
更新
根据您的评论:
I did not think it would work fine ! ... It is a problem in Substance; the L&F i am using.
有关该错误的详细信息,请参阅下文:
Substance: Editable JComboBox does not support backspace key
如上所述:
This behavior is by design. This is a "feel" part of Substance that adds auto-completion on editable comboboxes.
或者查看我的回答 here了解更多 L&F 和/或制作自己的 L&F 的方法
更新2:
感谢@Brad(破译了我从 Substance 链接的错误日志:P)来解决这个问题:
UIManager.put( LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE );
关于Java - 允许在带有 Substance L&F 的可编辑 JComboBox 中使用退格键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17391362/
我是一名优秀的程序员,十分优秀!