protected void customizePopup(BasicComboPopup popup) { scrollPane = getScrollPane(popup); if (popupWider) popupWider(popup); checkHorizontalScrollBar(popup); // For some reason in JDK7 the popup will not display at its preferred // width unless its location has been changed from its default // (ie. for normal "pop down" shift the popup and reset) Component comboBox = popup.getInvoker(); Point location = comboBox.getLocationOnScreen(); if (popupAbove) { int height = popup.getPreferredSize().height; popup.setLocation(location.x, location.y - height); } else { int height = comboBox.getPreferredSize().height; popup.setLocation(location.x, location.y + height - 1); popup.setLocation(location.x, location.y + height); } }
/* * I can't find any property on the scrollBar to determine if it will be * displayed or not so use brute force to determine this. */ protected int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) { int scrollBarWidth = 0; JComboBox comboBox = (JComboBox) popup.getInvoker(); if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) { JScrollBar vertical = scrollPane.getVerticalScrollBar(); scrollBarWidth = vertical.getPreferredSize().width; } return scrollBarWidth; }