views:

30

answers:

1

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

A: 

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