问题描述
望哪位大神指点下,万分感谢啊!!!
解决方案
解决方案二:
classLargerComboBoxUIextendsBasicComboBoxUI{publicvoidinstallUI(JComponentcomboBox){super.installUI(comboBox);}protectedComboPopupcreatePopup(){returnnewLargerComboPopup(comboBox);}publicclassLargerComboPopupextendsBasicComboPopup{publicLargerComboPopup(JComboBoxcomboBox){super(comboBox);}publicvoidshow(){intselectedIndex=comboBox.getSelectedIndex();if(selectedIndex==-1){list.clearSelection();}else{list.setSelectedIndex(selectedIndex);list.ensureIndexIsVisible(selectedIndex);}Insetsinsets=getInsets();DimensionlistDim=list.getPreferredSize();booleanhasScrollBar=scroller.getViewport().getViewSize().height!=listDim.height;if(hasScrollBar){JScrollBarscrollBar=scroller.getVerticalScrollBar();listDim.width+=scrollBar.getPreferredSize().getWidth();}intwidth=Math.max(listDim.width,comboBox.getWidth()-(insets.right+insets.left));intheight=getPopupHeightForRowCount(comboBox.getMaximumRowCount());RectanglepopupBounds=computePopupBounds(0,comboBox.getHeight(),width,height);DimensionscrollSize=popupBounds.getSize();scroller.setMaximumSize(scrollSize);scroller.setPreferredSize(scrollSize);scroller.setMinimumSize(scrollSize);list.revalidate();show(comboBox,popupBounds.x,popupBounds.y);}}}
这是重写的源代码
解决方案三:
居然没人回复