开发者

Change the size of a scrollbar in JComboBox

开发者 https://www.devze.com 2023-01-06 16:50 出处:网络
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

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

精彩评论

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