如何在jcombobox中更改jpopupmenu的高度? [英] How to change height of a jpopupmenu in a jcombobox?

查看:71
本文介绍了如何在jcombobox中更改jpopupmenu的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中我通过可编辑的"JComboBox"处理键释放事件,其中每个键释放上都显示"JComboBox"的"JPopupMenu".我想增加高度,以便用户无需滚动即可一目了然地看到更多项目. 有人可以演示如何故意设置'JPopupMenu'的高度,以便显示大量项目吗? 到目前为止,我已经尝试过了,但是没有用.

I am working on an application in which I am handling key release event over a editable 'JComboBox', where on every key release a 'JPopupMenu' of the 'JComboBox' appears. I want to increase the height so that user will be able to see more items at a glance without scrolling. Can anyone please demonstrate how to set the height of 'JPopupMenu' deliberately so that it will show considerable amount of items? So far i have tried this, but it doesn not work.

combo.getComponentPopupMenu().setSize(10, 10);

推荐答案

尝试以下操作:

ComboPopup popup = (ComboPopup) combo.getUI().getAccessibleChild(combo, 0);
((JComponent) popup).setPreferredSize(size);
((JComponent) popup).setLayout(new GridLayout(1, 1));

很高兴看到您的 SSCCE ,因此我可以测试我的建议是否有效.

It wold be nice to see your SSCCE, so I can test whether my proposal works.

这篇关于如何在jcombobox中更改jpopupmenu的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆