开发者

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 开发者_JAVA百科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);
      }
   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜