JComboBox自动选择列表中的第一项
我有一个 JComboBox,其中有一些可选项目。我的问题是,当用户单击 JComboBox 时,列表会按预期显示,但是当他决定不选择任何项目而只是单击框架上的其他任何位置时,JComboBox 会自动选择列表中的第一个项目。如何避免这种情况,不选择第一项,而是选择最后一项?我想我需要重写 JComboBox 侦听器或其他东西!?
Possible Duplicate:
How to configure JComboBox not to select FIRST element when created?
I have a JComboBox with a few selectable items in it. My problem is when the user click on the JComboBox, the list shows up as expected, but when he decide not to select any item and just clicks anywhere else on the frame, the JComboBox selects automatically the first item in the list. How do I avoid that, to not select the first item instead, to select the last one that was selected? I suppose that I need to override an JComboBox listener or something !?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的方法是提供您自己的 ComboBoxModel 来处理您的情况。不幸的是,实现这一目标并不容易。主要在只读 CB 中,正确识别用户手势确实很棘手。
The best way is to provide your own ComboBoxModel which handle your case. Unfortunately, it is not easy to make this happen. Mainly in Read-Only CB it can be really tricky to identify user gesture correctly.