How to change height of a jpopupmenu in a jcombobox?

百般思念 提交于 2019-12-12 01:44:07

问题


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);

回答1:


Try following:

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

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



来源:https://stackoverflow.com/questions/36175488/how-to-change-height-of-a-jpopupmenu-in-a-jcombobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!