Skip to content
Advertisement

How to change height of a jpopupmenu in a jcombobox?

enter image description here

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

Advertisement

Answer

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.

Advertisement