如何防止JComboBox下拉列表超出垂直屏幕尺寸
我使用包含许多条目(数百个)的 JComboBox。我想将其下拉列表的大小限制为屏幕的垂直大小。对于不同的外观和感觉以及屏幕分辨率,使用固定尺寸无法正常工作。
我在 Windows 7 上使用 Java 6u25。
如果我将最大行数设置为超过屏幕上适合的列表项(=行)数 (75) 的值(例如 100),则下拉列表似乎以全尺寸绘制,但最低的条目永远不可见。
这是用于说明的屏幕截图(感谢 @trashgod 的 SSCCE)。截图是在 XP 虚拟机中拍摄的。
我还在另一台电脑上测试了代码,所以我认为我可以排除一些驱动程序问题。
我喜欢的是一个适合屏幕的下拉列表,我可以在其中完全向下滚动到最后一个值(并查看该值)。相反,我想看到滚动条的向下滚动按钮。
渲染列表单元格并在我的计算中使用它的唯一可能性是什么?组合框高度参数的操作不起作用。
有什么想法如何解决这个问题吗?
令我困惑的是,我没有找到任何与该问题相关的内容。我认为我要么在这里遗漏了一些明显的东西,要么我在搜索中使用了错误的关键字。如果是后两者中的任何一个,我很抱歉,请给我一个提示。
谢谢。
I use a JComboBox with many entries (hundreds). I want to limit the size of its drop-down list to the vertical size of the screen. Using a fixed size does not work out properly for different look&feels and screen resolutions.
I am using Java 6u25 on Windows 7.
If I set the maximum row count to a value (e.g. 100) that exceeds the number of list items (=rows) that fit on the screen (75), the drop-down list seems to be drawn in full size but the lowest entries are never visible.
Here is a screenshot for illustation (thanks for the SSCCE by @trashgod). The sceenshot was taken in a virtual machine on XP.
I also tested the code on another PC, so I think I can rule out some driver issues.
What I like to have is a drop-down list that fits on screen where I can scroll down completely to the very last value (and see that value). The other way round, I would like to see the scroll down button of the scrollbar.
Is the only possibility to render a cell of the list and use this in my calculations? Manipulation of height parameters of the combobox did not work.
Any ideas how to solve this?
What puzzles me is that I did not find any reference to that problem whatsoever. I assume that I am either missing something obvious here or that I am using the wrong keywords for my search. If any of the latter two, my apologies please give me a hint.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的怀疑是有根据的;我的描述是基于对远程实现的遥远记忆。通过下面的 sscce,我看到了一个滚动条和 @uhm 报告的截断;我只能使用键盘从最后六个隐藏条目中进行选择。我在这些平台上得到了类似的结果:
Your skepticism is well founded; my description was based on a distant memory of a remote implementation. With the sscce below, I see a scroll bar and the truncation reported by @uhm; I can only select from among the last, half-dozen, hidden entries by using the keyboard. I get similar results on these platforms:
我找到了这个例子:http://www.javaprogrammingforums。 com/awt-java-swing/11457-jcombobox-scroll-bars.html(在底部)
I found this example: http://www.javaprogrammingforums.com/awt-java-swing/11457-jcombobox-scroll-bars.html (at the bottom)