2015-10-20 97 views
0

我想通過刪除舊的anchorPane.Now加載一個新的anchorPane在現有的場景中,我需要顯示用戶加載遊標和用戶執行的操作不應該發生(如按鈕點擊或按鍵)。加載新的anchorPane JavaFX遊標等待

我已經使用但Cursor.WAIT但仍然可以執行操作。

anchorPane.getScene()。SetCursor(Cursor.WAIT);

HomeController controller=new HomeController(stage,anchorPane); 
    FXMLLoader loader = new FXMLLoader(); 
    loader.setLocation(getClass().getResource("/fxml/home.fxml")); 
    loader.setController(controller); 
    Parent root = null; 
    try { 
     root=(Parent) loader.load(); 
    } catch (IOException e) { 
     LOGGER.error("Message is " + e); 
     e.printStackTrace(); 
    } 

    anchorPane.getChildren().remove(0); 
    anchorPane.getChildren().add(root); 

我這個code.but我不工作之前已經添加Cursor.WAIT。

+0

看一看[如何顯示在JavaFX的窗格的中心ProgressIndicator ...](http://stackoverflow.com/questions/32794379/how-to-show-progressindicator-in-center- of-pane-in-javafx) – ItachiUchiha

回答

0

Cursor.WAIT只更改光標的圖標,但它並不妨礙您與視圖進行交互。如果你想阻止用戶與你的視圖交互,你可以禁用像btn.setEnabled(false)這樣的元素。

要向用戶顯示您正在執行一些後臺操作,並且他/她應該等到完成後才能使用任務和對話框。

Task task = new Task(new Runnable() { ... do stuff ... }); 
    Dialog dialog = new Alert(AlertType.INFORMATION); 
    dialog.setTitle("Wait"); 
    dialog.disableButton(ButtonType.OK); 
    task.stateProperty().addListener(
      (observableValue, oldState, newState) -> { 
       if (newState == Worker.State.SUCCEEDED 
         || newState == Worker.State.FAILED 
         || newState == Worker.State.CANCELLED) { 
        dialog.close(); 
       } 
      }); 
    new Thread(task).start(); 
    dialog.showAndWait(); 
+0

不禁用我不能做其他事情。因此,用戶可以知道它的加載? –

+0

我更新了包含這個問題的答案 –

+0

我已經試過了,但現在我需要在一個線程內部打開一個對話框。可以嗎?我這樣做是拋出錯誤。 –