有人知道如何手动更改jComboBox中的滚动条大小吗?我尝试了很多东西,没有任何作用。
答案 0 :(得分:6)
好的,我想出来了。您可以实现PopUpMenuListener并使用它:
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);
}
}