How to change the size of scrollbar in JComboBox?

Sometimes we need to change the size of vertical scrollbar then we can use PopupMenuEvent.
We can get popup object from the JComboBox and then we can get JScrollPane component.
From JScrollPane component we need to get JScrollBar , using this instance we can change the dimensions of this scrollbar as follows.


public void popupMenuWillBecomeVisible(PopupMenuEvent e)
{
JComboBox comboSbBox = (JComboBox) e.getSource();
Object popup = comboSbBox.getUI().getAccessibleChild(comboSbBox , 0);
Component c = ((Container) popup).getComponent(0);
if (c instanceof JScrollPane)
{
JScrollPane spane = (JScrollPane) c;
JScrollBar scrollBar = spane .getVerticalScrollBar();
Dimension scrollBarDim = new Dimension(SCROLLBAR_WIDTH, scrollBar
.getPreferredSize().height);
scrollBar.setPreferredSize(scrollBarDim);
}
}

Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment