we use a spreadsheetview with different kind of cell types.
In the documentation to SpreadsheetCellEditor we found the following text:
The policy regarding validation of a given value is defined in SpreadsheetCellType.match(Object). If the value doesn't meet the requirements when saving the cell, nothing happens and the editor keeps editing.
now we facing the following problem:
if you enter "abcd" in an integer cell as a wrong entry and push enter key, nothing happens. Editor is still in edit mode. This is exactly the behaviour as descripted in the documentation. that is what we want.
if you have a date cell and enter a wrong date or something else and push enter key, cell stops editing mode and set value return to "old" value.
how can we prevent this behaviour? Maybe its a bug in the Date SpreadsheetCellType?
we use a lot of custom cellType Classes, but the behaviour is also comprehensibly with this little example.
I hope everything is well explained.
Thanks for your help.
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);
}
}
Update: are there no controlsfx experts?
Solved: https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A