-1

I have created a custom tablecell that changes to edit mode clicking by an option menu over that cell and doesnt change to read only view until the save button is pclicked. Now I have included that process in a thread to change the cursor to wait and not change to normal until it is finished. My problem is the cursor doesnt stay in waiting mode in all the view, if I am moving the cursor over any cell in edit mode the cursor changes to write mode instead of staying the waiting cursor. If anyone could help me, thanks in advance.

btSave.setOnAction((event) -> {
         final Task task = new Task<Void>() {
            @Override
            protected Void call() throws InterruptedException {
               try {
                  root.setCursor(Cursor.WAIT);
                  Set<Node> cells = table.lookupAll(".table-cell");
                  for (Node node : cells) {
                      TableCell<?, ?> cell = (TableCell<?, ?>) node;
                      if (cell.getGraphic() instanceof TextField) {
                         cell.getGraphic().setCursor(Cursor.WAIT);
                      }
                  }
                  int first = GuiUtil.getIndexToScroll(tvKontiMonths);
                  DataBean dataBean = new DataBean(table.getItems(),
                        results.isLevel());
                  Map<String, Boolean> listUpdates = (Map<String, Boolean>) DataProvider.getInstance()
                        .updateData(dataBean);
                  table.setCursor(Cursor.DEFAULT);
                  root.setCursor(Cursor.DEFAULT);
                  resetEditProperties();
                  refreshWithManualCells(listUpdates);
                  tvKontiMonths.scrollTo(first);
                  tvKonti.scrollTo(first);

               } catch (Exception e) {

               }
               return null;
            }
         };
         new Thread(task).start();
      });
  • 1
    your question will most probably be closed if you don't follow my earlier suggestion .. snippets without context are not enough for useful help! – kleopatra Jan 31 '19 at 16:26

1 Answers1

0

I'm not exactly sure how you are setting the cursor but if you want to set the cursor to be "waiting" for the whole scene I would do something like node.getScene().setCursor(Cursor.WAIT); this is because it will set that cursor for all of the children nodes so if you just wanted that cursor for just the table you could set table.setCursor(Cursor.WAIT);

EDIT: Give this a shot you should only need to set it on the scene and the child nodes should also take the property so I commented out the setting of the other nodes

btSave.setOnAction((event) -> {
    final Task task = new Task<Void>() {
        @Override
        protected Void call() throws InterruptedException {
            try {
                //root.setCursor(Cursor.WAIT);
                //Set<Node> cells = table.lookupAll(".table-cell");
                //for (Node node : cells) {
                //    TableCell<?, ?> cell = (TableCell<?, ?>) node;
                //    if (cell.getGraphic() instanceof TextField) {
                //        cell.getGraphic().setCursor(Cursor.WAIT);
                //    }
                //}
                btSave.getScene().setCursor(Cursor.WAIT);
                int first = GuiUtil.getIndexToScroll(tvKontiMonths);
                DataBean dataBean = new DataBean(table.getItems(),
                        results.isLevel());
                Map<String, Boolean> listUpdates = (Map<String, Boolean>) DataProvider.getInstance()
                        .updateData(dataBean);
                //table.setCursor(Cursor.DEFAULT);
                //root.setCursor(Cursor.DEFAULT);
                btSave.getScene().setCursor(Cursor.DEFAULT);
                resetEditProperties();
                refreshWithManualCells(listUpdates);
                tvKontiMonths.scrollTo(first);
                tvKonti.scrollTo(first);

            } catch (Exception e) {

            }
            return null;
        }
    };
    new Thread(task).start();
});

Also here is a runnable example:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Button button = new Button("Wait Cursor");
        button.setOnAction(event ->
                new Thread(()->{//Imitating your threading

                    //Show that stuff is being processed
                    button.getScene().setCursor(Cursor.WAIT);

                    //process some stuff
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //finished processing change cursor back
                    button.getScene().setCursor(Cursor.DEFAULT);

                }).start()
        );

        VBox vBox = new VBox();
        vBox.getChildren().add(button);

        //It looked empty so I added labels lol
        for(int i =0; i<10;i++)
            vBox.getChildren().add(new Label("Fake Node Number " + i));

        Stage stage  = new Stage();
        stage.setScene(new Scene(vBox));
        stage.show();
    }

    public static void main(String[] args) { launch(args); }
}
Matt
  • 3,052
  • 1
  • 17
  • 30
  • @FernandoGuerreroFuente I made some edits take a look if this satisfies your question click the check next to the answer so others no longer think its open. Let me know if you have any other questions. – Matt Jan 31 '19 at 19:19
  • Thanks a lot for your help, it works much better but still is not entirely workingl, if I move the cursor over a cell in editing mode while it is in the proccess of saving, the cursor changes to edit mode, I edit my post with some screens. – Fernando Guerrero Fuente Feb 01 '19 at 07:59
  • 1
    @FernandoGuerreroFuente screenshots are not helpful anyway, what you need to provide is a [mcve] which you still insist on not providing ... – kleopatra Feb 01 '19 at 09:11
  • Sorry, when I am free of time, I will provide a funtional example. – Fernando Guerrero Fuente Feb 01 '19 at 11:13
  • if you don't have the time to post reasonable questions, don't post them at all - without proper care it's a waste of time for all involved ;( – kleopatra Feb 01 '19 at 14:06