Change the size of a scrollbar in JComboBox

橙三吉。 提交于 2019-12-12 21:30:37

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/3207127/change-the-size-of-a-scrollbar-in-jcombobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!