我是JavaFX和ControlsFX的新手。ControlsFX SpreadsheetView rowspan IndexOutOfBoundsException
我正在尝试使用ControlsFX库创建一个非常基本的SpreadsheetView。以下是该函数来填充和创建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: Index: 2, Size: 2 at java.util.ArrayList.rangeCheck(ArrayList.java:653)
我知道它的发生,因为我没有加入对的rowIndex = 1的任意值colIndex = 1(请参见注释掉的一行)......但这正是我想要的。
row0-col1 has a rowspan of 2
这应该表示即使我的row1-col1不存在,也不应该有任何问题。
为什么ControlsFX不会自动处理这个问题?
如果我取消那行,我得到下面的输出:
编辑1:
而且,我发现了另一个问题,当合并单元格/行跨度占据整个列/行,然后当您按下箭头键导航到单元格时,会出现错误:
上述情况,当你按下右箭头键(虽然他们是不是在右侧的单元格)