如何将文本字段的焦点移动到下面的文本字段按ENTER,我不想将文本字段更改为只读。我试图获得当前的焦点,但单元格并不只关注文本域,但我不知道如何获得它。
答案 0 :(得分:0)
尝试在yourNextTextField.requestFocus()
中使用yourCurrentTextField.setOnAction()
。
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author blj0011
*/
public class JavaFXApplication200 extends Application
{
@Override
public void start(Stage primaryStage)
{
TextField textField1 = new TextField();
TextField textField2 = new TextField();
TextField textField3 = new TextField();
textField1.setOnAction((event) -> {
//Do some stuff
textField2.requestFocus();
});
textField2.setOnAction((event) -> {
//Do some stuff
textField3.requestFocus();
});
textField3.setOnAction((event) -> {
//Do some stuff
textField1.requestFocus();
});
Parent root = new VBox(textField1, textField2, textField3);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}