Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8120102

Stage.requestFocus doesn't work as expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • 8
    • javafx
    • None
    • jdk8.0 b89

      To reproduce run attached code.
      Click on some application to lose focus. And wait 3 seconds.

      On Macos you won't get focused state(just like toFront method).
      On Windows you will get focused property equals true, but application won't receive input from keyboard

      public class Bug extends Application {

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
              // TODO code application logic here
          }

          @Override
          public void start(Stage stage) throws Exception {
              stage.setScene(new Scene(new HBox(new Button("One"),new Button("two")), 200, 200));
              stage.show();
              new Thread(() -> {
                  while (true) {
                      Platform.runLater(() -> {
                          stage.requestFocus();
                          
                              });
                      try {
                          Thread.sleep(3000);
                      } catch (Exception ex) {
                      }
                  }
              }).start();
              new Thread(()->{while(true){
                  Platform.runLater(()->System.out.println("Focused"+stage.isFocused()));
                  Platform.runLater(()->System.out.println("Showing"+stage.isShowing()));
                  try{
                      Thread.sleep(2000);
                  }catch(Exception ex){
                      
                  }
              }}).start();
          }

      }

            art Artem Ananiev (Inactive)
            anazarov Andrey Nazarov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: