设置自定义 UI 后 JComboBox 丢失键盘事件
我有以下问题:
我需要为 JComboBoxComponent
设置自定义 UI(以修改颜色、箭头按钮等)。目前,我正在构造函数中执行此操作,如下所示:
public MyComboBox() {
setUI(new MyComboBoxUI);
}
问题是,以这种方式设置 UI 后,我以某种方式释放了组合框弹出窗口中列表的所有 InputMap
和 ActionMap
内容,即它不会使用箭头键向上或向下滚动列表。
我在这里做错了什么?
这是代码:
public class CurrencyPairComboBox extends JComboBox {
public CurrencyPairComboBox() {
setUI(new CurrencyPairComboBoxUI());
}
}
class CurrencyPairComboBoxUI extends BasicComboBoxUI {
@Override
public void installUI(JComponent c) {
super.installUI(c);
listBox.setSelectionBackground(Color.BLACK);
listBox.setSelectionForeground(Color.WHITE);
}
@Override
protected JButton createArrowButton() {
arrowButton = new JButton();
arrowButton.setIcon(OrderWidgetUIConstants.DROPDOWN_ARROW_ICON);
arrowButton.setRolloverIcon(OrderWidgetUIConstants.DROPDOWN_ARROW_HOVER_ICON);
return arrowButton;
}
}
I have the following problem :
I need to set a custom UI for a JComboBoxComponent
(to modify colors, arrow button etc.) Currently, I'm doing it in a constructor, like this :
public MyComboBox() {
setUI(new MyComboBoxUI);
}
Problem is, after setting UI in such way, I somehow loose all InputMap
and ActionMap
contents for list in combo box popup, i.e. it doesn't scroll list up or down with arrow keys.
What am I doing wrong here?
Here's the code :
public class CurrencyPairComboBox extends JComboBox {
public CurrencyPairComboBox() {
setUI(new CurrencyPairComboBoxUI());
}
}
class CurrencyPairComboBoxUI extends BasicComboBoxUI {
@Override
public void installUI(JComponent c) {
super.installUI(c);
listBox.setSelectionBackground(Color.BLACK);
listBox.setSelectionForeground(Color.WHITE);
}
@Override
protected JButton createArrowButton() {
arrowButton = new JButton();
arrowButton.setIcon(OrderWidgetUIConstants.DROPDOWN_ARROW_ICON);
arrowButton.setRolloverIcon(OrderWidgetUIConstants.DROPDOWN_ARROW_HOVER_ICON);
return arrowButton;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了您在此处发布的代码,我没有看到任何键盘问题,一切都按我的预期工作
I tried code that you posted here, I didn't see any Keyboard issue(s), all works as I expected