Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将如何以编程方式设置JComboBox要选择的状态并在下拉列表中显示其内容?
JComboBox
尝试使用设置选定的索引:setSelectedItem(Object item)或setSelectedIndex(int index)然后调用您的JComboBox实例:
setSelectedItem(Object item)
setSelectedIndex(int index)
jComboBox.showPopup(); //or //jComboBox.setPopupVisible(true);
如果您希望它在一段时间内可见,只需在一段时间后使用 SwingTimer调用即可setPopupVisible(false);。
Timer
setPopupVisible(false);
参考资料: