【问题标题】:ControlsFx - Spreadsheetview - DateCell - keep editing on failureControlsFx - 电子表格视图 - DateCell - 在失败时继续编辑
【发布时间】:2019-03-05 20:13:31
【问题描述】:

我们使用具有不同类型单元格类型的电子表格视图。

SpreadsheetCellEditor 的文档中,我们发现了以下文本:

关于验证给定值的策略定义在 SpreadsheetCellType.match(对象)。如果值不符合要求 保存单元格时,没有任何反应,编辑器继续编辑。


现在我们面临以下问题:

如果您在整数单元格中输入“abcd”作为错误条目并按下回车键,则不会发生任何事情。编辑器仍处于编辑模式。这正是文档中描述的行为。这就是我们想要的。

如果您有一个日期单元格并输入错误的日期或其他内容并按回车键,则单元格将停止编辑模式并将值返回为“旧”值。

我们如何防止这种行为? 也许它是 Date SpreadsheetCellType 中的错误?

我们使用了很多自定义的 cellType 类,但是通过这个小例子也可以理解行为。

我希望一切都得到很好的解释。

感谢您的帮助。

import java.time.LocalDate;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.controlsfx.control.spreadsheet.GridBase;
import org.controlsfx.control.spreadsheet.SpreadsheetCell;
import org.controlsfx.control.spreadsheet.SpreadsheetCellType;
import org.controlsfx.control.spreadsheet.SpreadsheetView;

public class SpreadSheetExample extends Application {

private SpreadsheetView getSpreadSheet() {
    SpreadsheetView spreadSheetView;
    GridBase grid;
    grid = new GridBase(10, 2);
    spreadSheetView = new SpreadsheetView(grid);

    ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
    for (int row = 0; row < grid.getRowCount(); ++row) {
        final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
        for (int column = 0; column < grid.getColumnCount(); ++column) {
            if (column < 1) {
                list.add(SpreadsheetCellType.DATE.createCell(row, column, 1, 1, LocalDate.now()));
            } else {
                list.add(SpreadsheetCellType.INTEGER.createCell(row, column, 1, 1, column));
            }

        }
        rows.add(list);
    }

    spreadSheetView.getColumns().forEach((column) -> {
        column.setPrefWidth(280);
    });

    grid.setRows(rows);

    return spreadSheetView;
}

@Override
public void start(Stage primaryStage) {

    StackPane root = new StackPane();
    root.getChildren().add(getSpreadSheet());

    Scene scene = new Scene(root, 800, 400);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}

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

}

更新: 没有 controlfx 专家吗?

已解决: https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A

【问题讨论】:

    标签: spreadsheet controlsfx


    【解决方案1】:

    解决了。 我从 ControlsFX 的主要贡献者之一那里得到了一些帮助。

    文档有点不清楚。 为了获得所描述的行为,可以创建一个基于现有的自定义单元类型 + 编辑器。

    有关所有详细信息,请查看此线程: https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-14
      • 2016-07-16
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多