JComboBox自动选择列表中的第一项

发布于 2024-12-14 02:08:17 字数 406 浏览 4 评论 0原文

可能的重复:
如何配置 JComboBox 不选择 FIRST元素何时创建?

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赏烟花じ飞满天 2024-12-21 02:08:17

最好的方法是提供您自己的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文