Is there any way to focus on JavaFX?

I know you can execute node Requestfocus() to focus on nodes in JavaFX But is there any way to remove focus from nodes in JavaFX or prevent focusing on objects?

Solution

I don't think there is any guarantee that this will always work, but you can try to set the focus to something that itself doesn't accept keyboard input (such as the layout pane):

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.V@R_500_2419@;
import javafx.stage.Stage;

public class NoFocusTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        TextField tf1 = new TextField();
        tf1.setPromptText("Enter something");
        TextField tf2 = new TextField();
        tf2.setPromptText("Enter something else");
        V@R_500_2419@ root = new V@R_500_2419@(5,tf1,tf2);
        primaryStage.setScene(new Scene(root,250,150));
        primaryStage.show();
        root.requestFocus();
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>