下面列出了javax.swing.plaf.basic.BasicComboPopup#getInvoker ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private 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);
//TODO should not be hardcoded
popup.setLocation(location.x + 5, location.y + 35);
}
}
protected void customizePopup(BasicComboPopup popup) {
scrollPane = getScrollPane(popup);
popupWider(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();
int height = comboBox.getSize().height;
popup.setLocation(location.x, location.y + height - 1);
popup.setLocation(location.x, location.y + height);
}
protected int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) {
// 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.
JComboBox<?> comboBox = (JComboBox) popup.getInvoker();
if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) {
return scrollPane.getVerticalScrollBar().getPreferredSize().width;
}
else {
return 0;
}
}
private int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) {
int scrollBarWidth = 0;
@SuppressWarnings("unchecked")
JComboBox<E> comboBox = (JComboBox<E>) popup.getInvoker();
if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) {
JScrollBar vertical = scrollPane.getVerticalScrollBar();
scrollBarWidth = vertical.getPreferredSize().width;
}
return scrollBarWidth;
}