简体   繁体   中英

JavaFX opposite function of .requestFocus()?

I'm looking for function in JavaFX, where I can "disable or dismiss" the requested focus.

Here is a screenshot of my program: Screenshot

Every cell is filled with an Eventhandler (onMouseEntered and onMouseExited) and in every onMouseEntered function I have to request the focus like this: label.requestFocus() . I need to do that, because I'm using KeyEvents to change the content of the cell.

It works fine, but there is a bug: When I move out of the scrollPane, there is still the requested focus on the last entered cell.

How can I solve that issue, without requesting focus for everything around the Scrollpane to fix this bug? Is there a function, where I can dismiss the requested focus, so after exiting a cell, it'll dismiss the focus.

Best regards,

My code:

 arbeitetLabel.setOnMouseEntered(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {

            arbeitetLabel.requestFocus();
            arbeitetLabel.setOnKeyPressed(new EventHandler<KeyEvent>() {

                @Override
                public void handle(KeyEvent keyEvent) {
                    // Do some keyEvent Stuff
                }
            });


        }

    });

    arbeitetLabel.setOnMouseExited(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            // Dismiss the requested Focus here?
        }

    });

我将焦点传递给了父母,就是这样!

arbeitetLabel.getParent().requestFocus()

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.

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