P. Pandey
P. Pandey

Reputation: 108

how to make JFXPanel to get focus if clicked anywhere on it not on children

I have JFXPanel with a textbox and few buttons on it. I want to lost focus of textbox if user click on anywhere other than child controls.

Upvotes: 1

Views: 156

Answers (1)

P. Pandey
P. Pandey

Reputation: 108

Here is my working example:

override the mouse click event of JFXPanel as follows:

          jfxPanel.addMouseListener(new MouseAdapter() {                    
                @Override
                public void mouseClicked(MouseEvent e) {
                    if(!toolbarJFX.getScene().getFocusOwner().isPressed()) {
                        toolbarJFX.getScene().getRoot().requestFocus();
                    }
                }

            });

Upvotes: 1

Related Questions