【问题标题】:Javafx tablecell change cursor wait in edit modeJavafx tablecell在编辑模式下更改光标等待
【发布时间】:2019-01-30 07:50:26
【问题描述】:

我创建了一个自定义表格单元格,该表格单元格通过单击该单元格上的选项菜单更改为编辑模式,并且在单击保存按钮之前不会更改为只读视图。现在我已经将该进程包含在一个线程中,以将光标更改为等待并且在完成之前不会更改为正常状态。我的问题是光标在所有视图中都没有停留在等待模式,如果我在编辑模式下将光标移动到任何单元格上,光标会变为写入模式而不是停留在等待光标。 如果有人可以帮助我,请提前致谢。

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();
      });

【问题讨论】:

  • 如果您不遵循我之前的建议,您的问题很可能会被关闭。没有上下文的 sn-ps 不足以提供有用的帮助!

标签: javafx cursor tableview wait tablecell


【解决方案1】:

我不确定您是如何设置光标的,但如果您想将光标设置为“等待”整个场景,我会执行node.getScene().setCursor(Cursor.WAIT); 之类的操作,因为它会为所有人设置该光标的子节点,所以如果你只想要那个表的光标,你可以设置table.setCursor(Cursor.WAIT);

编辑:试一试,您只需要在场景中设置它,子节点也应该获取该属性,所以我注释掉了其他节点的设置

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();
});

这里还有一个可运行的例子:

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); }
}

【讨论】:

  • @FernandoGuerreroFuente 我做了一些编辑,看看这是否满足您的问题,请单击答案旁边的检查,以便其他人不再认为它是开放的。如果您有任何其他问题,请告诉我。
  • 非常感谢您的帮助,它工作得更好,但仍然不能完全工作l,如果我在保存过程中将光标移到处于编辑模式的单元格上,光标会变为编辑模式,我用一些屏幕编辑我的帖子。
  • @FernandoGuerreroFuente 截图无论如何都没有用,你需要提供的是minimal reproducible example,你仍然坚持不提供...
  • 对不起,有空我会提供一个功能性的例子。
  • 如果您没有时间发布合理的问题,请不要发布它们 - 没有适当的照顾,这对所有相关人员来说都是浪费时间;(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-08
  • 1970-01-01
  • 2019-06-03
  • 2012-03-29
  • 2017-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多