I want when :

comboBox.getSelectedIndex() == 1

Then system focus should set to my textField1 .

this is my code:

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == comboBox) {
        if (comboBox.getSelectedIndex() == 1) {

            // set focus to textField1
        }
    }
}
有帮助吗?

解决方案

component.requestFocusInWindow();

其他提示

Try textField1.requestFocus();

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == comboBox) {
        if (comboBox.getSelectedIndex() == 1) {

            // set focus to textField1
            textField1.requestFocus();
        }
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top