0

i tried

public void ChangeFocus(Button browse, final FlowPane mFlowPane)
{
    browse.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

         @Override
         public void handle(KeyEvent event)
         {
             if (event.getCode() == KeyCode.TAB)
             {
                System.out.println("TAB pressed");
                mFlowPane.requestFocus();
                event.consume(); // do nothing
         }
       }
     });

}

in above code i set one ImageView inside Flowpane but when i press TAB button on my browse button i can't get focus on imageview how can i solve it?

2 Answers2

2

FlowPane is not focustraversable by default. Call mFlowPane.setFocusTraversable(true) to make it part of the traverse story

tomsontom
  • 5,856
  • 2
  • 23
  • 21
2

some more detail to solve it. instead of focusing the flowpane you need to set the focus on whats in the flowpane, for example a textfield:

flowPane.setOnMouseClicked(new EventHandler<MouseEvent>()
{
   public void handle(MouseEvent mouseEvent)
   {
         textfield.requestFocus();
   }
});
tonimaroni
  • 1,062
  • 10
  • 19
  • thanks - this saved my day :-). if you answer this here: http://stackoverflow.com/questions/31320018/javafx-key-press-not-captured you will get accepted. – dermoritz Jul 09 '15 at 16:03