【发布时间】:2017-05-14 12:52:21
【问题描述】:
我是 JavaFX 和 ControlsFX 的新手。
我正在尝试使用 ControlsFX 库创建一个非常基本的 SpreadsheetView。以下是填充和创建电子表格视图的函数:
private fun spreadSheetFunc() : SpreadsheetView {
val rowCount = 15
val columnCount = 10
val grid = GridBase(rowCount, columnCount)
val rows = FXCollections.observableArrayList<ObservableList<SpreadsheetCell>>()
var list = FXCollections.observableArrayList<SpreadsheetCell>()
list.add(SpreadsheetCellType.STRING.createCell(0, 0, 1, 1, "row0-col0"))
list.add(SpreadsheetCellType.STRING.createCell(0, 1, 2, 1, "row0-col1"))
list.add(SpreadsheetCellType.STRING.createCell(0, 2, 1, 1, "row0-col2"))
rows.add(list)
list = FXCollections.observableArrayList()
list.add(SpreadsheetCellType.STRING.createCell(1, 0, 1, 1, "row1-col0"))
//commenting row1-col1 as row0-col1 has a rowspan of 2
//list.add(SpreadsheetCellType.STRING.createCell(1, 1, 1, 1, "row1-col1"))
list.add(SpreadsheetCellType.STRING.createCell(1, 2, 1, 1, "row1-col2"))
rows.add(list)
list = FXCollections.observableArrayList()
list.add(SpreadsheetCellType.STRING.createCell(2, 0, 1, 1, "row2-col0"))
list.add(SpreadsheetCellType.STRING.createCell(2, 1, 1, 1, "row2-col1"))
list.add(SpreadsheetCellType.STRING.createCell(2, 2, 1, 1, "row2-col2"))
rows.add(list)
list = FXCollections.observableArrayList()
list.add(SpreadsheetCellType.STRING.createCell(3, 0, 1, 1, "row3-col0"))
list.add(SpreadsheetCellType.STRING.createCell(3, 1, 1, 1, "row3-col1"))
list.add(SpreadsheetCellType.STRING.createCell(3, 2, 1, 1, "row3-col2"))
rows.add(list)
grid.setRows(rows)
return SpreadsheetView(grid)
}
运行时出现以下错误:
java.lang.IndexOutOfBoundsException:索引:2,大小:2 java.util.ArrayList.rangeCheck(ArrayList.java:653)
我知道它正在发生,因为我没有为 rowIndex=1 colIndex=1 添加任何值(请参阅注释掉的行)......但这就是我想要的。
row0-col1 has a rowspan of 2 应该意味着即使我的 row1-col1 不存在,也不应该有任何问题。
为什么 ControlsFX 不自动处理这个问题?
如果我取消注释该行,我会得到以下输出:
编辑 1:
另外,我发现了另一个问题,当 colspan/rowspan 占据了 SpreadsheetView 中的整个列/行,然后当你按下箭头键导航到单元格时,你会得到一个错误:
当您按右箭头键时会出现上述情况(即使它们不是右侧的单元格)
【问题讨论】:
标签: javafx spreadsheet kotlin controlsfx