简体   繁体   English

JavaFX硬焦点丢失在其他窗口区域上单击

[英]JavaFX hard focus lost on other window area click

I have some trouble with taking off focus from TextField in JavaFX application... 我在从JavaFX应用程序的TextField中移出焦点时遇到了一些麻烦...

When there are few TextFields on window layout I can click on another one and it will be "re-focused", it's OK. 当窗口布局上的TextField很少时,我可以单击另一个,然后将其“重新聚焦”,就可以了。

The thing I want to do is to fill my TextField; 我要做的是填充我的TextField; after I done with filling I want to click somewhere else on app-window-area (not on other TextField) and it must take off focus from my Textfield. 完成填充后,我想在应用程序窗口区域(而不是其他TextField)上单击其他位置,并且它必须使我的Textfield失去焦点。

I've googled for a few hour and there is no result... CSS modification will be acceptable too. 我已经搜索了几个小时,没有结果... CSS修改也可以接受。

Hope for your help or ideas! 希望您的帮助或想法!

Thanx in advance. 提前感谢。

Focus has to be somewhere , so really the idea is, if you want nothing that either has visual recognition of being focused, or responds to keyboard input, to have the focus then you have to put focus on a component that does neither of those things. 焦点必须在某个地方 ,所以真正的想法是,如果您不希望通过视觉识别焦点或响应键盘输入来获得焦点,则必须将焦点放在既不执行上述操作又不执行任何操作的组件上。

So for example: 因此,例如:

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class UnfocusTextField extends Application {

    @Override
    public void start(Stage primaryStage) {
        GridPane root = new GridPane();
        root.setOnMousePressed(e -> root.requestFocus());
        root.setAlignment(Pos.CENTER);
        root.setHgap(10);
        root.setVgap(10);
        for (int i = 0 ; i < 10; i++) {
            root.add(new TextField(), i % 2, i / 2 );
        }
        Scene scene = new Scene(root, 600, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM