ControlsFX SpreadsheetView rowspan IndexOutOfBoundsException
我是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:
而且,我发现了另一个问题,当合并单元格/行跨度占据整个列/行,然后当您按下箭头键导航到单元格时,会出现错误:
上述情况,当你按下右箭头键(虽然他们是不是在右侧的单元格)
让我道歉,因为它没有很好的记载如何跨度必须在SpreadsheetView进行产生。我会更新文档。
如果您想要跨度,则必须在跨度内的每个单元格中放置相同的单元格。因此,要么你建立你自己的细胞,然后在每个地方。在你的情况下,你可以在第0行第1列和第1行第1列中添加相同的单元格。 或者你可以保留你的代码,并简单地在网格上调用方法。此方法会自动将您的单元格放置并相应地放置它。
关于第二个问题,请提交给我们的问题追踪器,以便我们能够解决这个问题:https://bitbucket.org/controlsfx/controlsfx/issues?status=new&status=open
如果您有任何关于SpreadsheetView其它问题,考虑在我们的谷歌组发布,我们会得到通知:http://groups.controlsfx.org