有没有办法改变JComboBox的项目焦点?

时间:2020-12-12 23:13:51

I can change the item's focus by pressing the arrow keys on the keyboard or by moving the mouse over it. Is there a programmatic way to move the focus around the items?

我可以通过按键盘上的箭头键或将鼠标移到键盘上来更改项目的焦点。是否有一种程序化的方式来围绕项目移动焦点?

1 个解决方案

#1


2  

You can simply set the selected item. Optionally, you can show the dropdown list:

您只需设置所选项目即可。 (可选)您可以显示下拉列表:

comboBox.requestFocus();
comboBox.showPopup();
comboBox.setSelectedIndex(selectedIndex);

#1


2  

You can simply set the selected item. Optionally, you can show the dropdown list:

您只需设置所选项目即可。 (可选)您可以显示下拉列表:

comboBox.requestFocus();
comboBox.showPopup();
comboBox.setSelectedIndex(selectedIndex);