문제

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