Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. //vars
  2. @FXML private ProgressIndicator loadingIndicator;
  3. private BooleanProperty isSaving = new SimpleBooleanProperty(false);
  4.  
  5. @Override
  6. public void initialize(URL location, ResourceBundle resources) {
  7. parentToDisable.disableProperty().bind(isSaving);
  8. loadingIndicator.visibleProperty().bind(isSaving);
  9. }
  10.  
  11.  
  12. @FXML
  13. void onSave(ActionEvent event) {
  14. isSaving.set(true); //<<<<<<<<<problem
  15. // separate non-FX thread
  16. new Thread() {
  17. // runnable for that thread
  18. public void run() {
  19.  
  20. //++++++++++//long running task......+++++++++++++++
  21.  
  22. // update ProgressIndicator on FX thread
  23. Platform.runLater(new Runnable() {
  24. public void run() {
  25. isSaving.set(false); //<<<<<<<<<problem
  26. }
  27. });
  28. }
  29. }.start();
  30. }
  31.  
  32. <ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="600.0"
  33. prefWidth="500.0" xmlns="http://javafx.com/javafx/8"
  34. xmlns:fx="http://javafx.com
  35. /fxml/1">
  36. <content>
  37. <StackPane>
  38. <children>
  39. <VBox fx:id="parentToDisable">
  40. <!-- shortened -->
  41. <Button fx:id="btnSave" mnemonicParsing="false" onAction="#onSave"
  42. text="Speichern" />
  43. <!-- shortened -->
  44. </VBox>
  45. <ProgressIndicator fx:id="loadingIndicator"
  46. maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
  47. minWidth="-Infinity" prefHeight="60.0" prefWidth="60.0"
  48. visible="false" />
  49. </children>
  50. </StackPane>
  51. </content>
  52. </ScrollPane>
  53.  
  54. public void initialize(...) {
  55. Platform.runLater(() -> loadingIndicator.visibleProperty().bind(isSaving));
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement