Tutorial :Change the size of a scrollbar in JComboBox


Does anybody know how to change the scrollbar size in jComboBox manually? I've tried a whole bunch of stuff and nothing works.


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »