如何在javafx表格视图中为一组单元格绘制边框

时间:2018-12-04 14:07:44

标签: javafx tableview

我有一个样本表。
我需要根据输入显示一组表格单元格的边框,如下图所示:

enter image description here

关键是,边框位置是动态的,它基于表的输入。我的表格数据可能很大,可以容纳25列和500行。我所拥有的信息是开始单元格和结束单元格的行索引和列索引。

我无法使用updateItem()函数,因为updateItem()中未显示的单元格将不会调用tableview。加载表后,我无法访问tablecell对象。

有没有办法在加载tableview之后动态setStyle到tableCells?

1 个答案:

答案 0 :(得分:0)

感谢提供了不同见解的评论。 我解决了这样的问题,

计算了我需要为其绘制边框的左上索引和右下索引。并在表单元格的updateItem()方法中使用了这些值,

`if(tableCol.getTableView()!= null){             A4CalculationIndexValues a4CalculationIndexValues = A4Calculation.A4LayoutDetails.get(tableCol.getTableView()。getId());             if(a4CalculationIndexValues!= null){             整数startRow = a4CalculationIndexValues.startRowColumnIndex.getRow();             整数startColumn = a4CalculationIndexValues.startRowColumnIndex.getColumn();             整数endColumn = a4CalculationIndexValues.endRowColumnIndex.getColumn();             整数endRow = a4CalculationIndexValues.endRowColumnIndex.getRow();

            if (getIndex() == startRow &&  columnIndex >= startColumn && columnIndex <= endColumn) {
                if (getStyle().equalsIgnoreCase(""))
                    setStyle("-fx-border-width: 1 2 3 4; -fx-border-color: red white white white");
            }
            if (getIndex() >= startRow && getIndex() <= endRow && columnIndex == startColumn) {
                if (getStyle().equalsIgnoreCase(""))
                    setStyle("-fx-border-width: 1 2 3 4; -fx-border-color: white white white red");
            }
            if (getIndex() == endRow && columnIndex >= startColumn && columnIndex <= endColumn) {
                if (getStyle().equalsIgnoreCase(""))
                    setStyle("-fx-border-width: 1 2 3 4; -fx-border-color: white white red white");
            }
            if (getIndex() >= startRow && getIndex() <= endRow && columnIndex == endColumn) {
                if (getStyle().equalsIgnoreCase(""))
                    setStyle("-fx-border-width: 1 2 3 4; -fx-border-color: white red white white");
            }
        }
    }`
相关问题