Reputation: 443
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);
Upvotes: 1
Views: 1475
Reputation: 326
A much cleaner approach with using only public API (and without hacks) is to:
Upvotes: 4
Reputation: 11327
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.
Upvotes: 5