【问题标题】:ControlsFX SpreadsheetView rowspan IndexOutOfBoundsExceptionControlsFX 电子表格视图行跨度 IndexOutOfBoundsException
【发布时间】: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


    【解决方案1】:

    让我道歉,因为没有很好地记录在电子表格视图中必须如何设置跨度。我会更新文档。

    如果你想跨度,你必须在跨度内的每个单元格中放置相同的单元格。 所以要么你建立自己的细胞,然后在每个地方。在您的情况下,您将在第 0 行第 1 列和第 1 行第 1 列中添加相同的单元格。 或者您可以保留您的代码,并在网格上调用spanRow 方法。此方法将自动获取您的单元格并相应地放置它。

    关于第二个问题,请将其提交给我们的问题跟踪器,以便我们修复它:https://bitbucket.org/controlsfx/controlsfx/issues?status=new&status=open

    如果您对 SpreadsheetView 有其他问题,请考虑在我们的 Google 群组中发帖,我们会收到通知:http://groups.controlsfx.org

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 2012-12-22
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多