0

因此,我一直在关注本教程,该教程告诉您如何在 TornadoFX 中制作数据网格,并且一切正常。但是,我想向数据网格的每个单元格添加多个视图,因此我想用边框窗格替换堆栈窗格。这打破了它。单元格仍然出现,但它们是空白的白色方块。没有一个视图出现在里面。我不太确定为什么会这样。在我看来, cellFormat 和 cellCache 就像 for-each 循环一样,在它们内部为需要格式化的单元格列表中的每个元素制作一个图形描述。不过,我不确定。因此,我真的不确定如何解决这个问题。如果有人能提供帮助,我真的很感激。

在每个白色方块上放置一个绿色圆圈和一个标签的代码:

    class DatagridDemo: View("Datagrid Demo") {

        val data = listOf("one", "two", "three")

        override val root = datagrid(data) {
            cellFormat {
                graphic = stackpane() {
                    circle(radius = 50.0) {
                        fill = Color.ALICEBLUE;
                    }
                    label(it);
                }
            }
        }

    }

我的代码:

    class DatagridDemo: View("Datagrid Demo") {

        val data = listOf("one", "two", "three")

        override val root = datagrid(data) {
            cellFormat {
                graphic = borderpane() {
//The widgets implement View()
                    top<TopWidget>();
                    bottom<BottomWidget>()
                    label(it);
                }
            }
        }

    }
4

1 回答 1

0

这使用两个自定义片段来创建添加到顶部和底部的对象。

class TopWidget(msg : String) : Fragment() {

    override val root = label(msg)
}

class BottomWidget(msg : String) : Fragment() {

    override val root = label(msg)
}

class DatagridDemo: View("Datagrid Demo") {

    val data = listOf("one", "two", "three")

    override val root = datagrid(data) {
        cellFormat {
            graphic = borderpane {
                top { add(TopWidget("Top ${it}")) }
                center { label(it) }
                bottom { add(BottomWidget("Bottom ${it}")) }
            }
        }
    }

}

class DGDemo : App(DatagridDemo::class)
于 2018-07-10T13:28:01.033 回答