如题, 下面代码是网上找的, 网上说可以让下拉列表向上显示, 还有截图, 我的运行结果怎么不行?import java.awt.BorderLayout;import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.plaf.basic.BasicComboPopup;public class PopupComboBox extends JComboBox { public PopupComboBox(Object[] values) {
super(values);
} public static void main(String[] args) { Object[] values = { "Zhang San", "Li Si", "Wang Wu", "Sun Liu" }; JFrame frame = new JFrame("Pop *UP* JComboBox");
JComboBox comboBox = new PopupComboBox(values);
frame.add(comboBox, BorderLayout.PAGE_START);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250, 150);
frame.setVisible(true);
} public void firePopupMenuWillBecomeVisible() {
BasicComboPopup popup = (BasicComboPopup) getUI().getAccessibleChild(
this, 0);
int height = popup.getHeight();
if (height == 0) {
height = popup.getPreferredSize().height;
}
popup.setLocation(getLocationOnScreen().x, getLocationOnScreen().y
- height);
super.firePopupMenuWillBecomeVisible();
}
}
运行结果如下图, (JDK1.7)