enter image description here The Code create a window,and there is a textfield in window.it is a search box.when I click the blank place or other place,I want that the textfield loss focus.
HBox pane = new HBox(); Label lb_search = new Label("search:"); TextField tf_search = new TextField(); pane.getChildren().addAll(lb_search,tf_search); Scene scene = new Scene(pane,400,200); primaryStage.setScene(scene); primaryStage.setTitle("search"); primaryStage.show();
By default, only controls can get focus in JavaFX. However, you can change this with setFocusTraversable
. Try changing this on the Node the TextField is contained in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.