Reputation: 91
Does anybody know how to change the scrollbar size in jComboBox manually? I've tried a whole bunch of stuff and nothing works.
Upvotes: 2
Views: 4482
Reputation: 91
Ok, I figured this out. You can implement PopUpMenuListener and use this:
public void popupMenuWillBecomeVisible(PopupMenuEvent e)
{
JComboBox comboBox = (JComboBox) e.getSource();
Object popup = comboBox.getUI().getAccessibleChild(comboBox, 0);
Component c = ((Container) popup).getComponent(0);
if (c instanceof JScrollPane)
{
JScrollPane scrollpane = (JScrollPane) c;
JScrollBar scrollBar = scrollpane.getVerticalScrollBar();
Dimension scrollBarDim = new Dimension(SCROLLBAR_WIDTH, scrollBar
.getPreferredSize().height);
scrollBar.setPreferredSize(scrollBarDim);
}
}
Upvotes: 7