Tornadofx: The gridpaneConstraints in a row works incorrectly

Created on 21 Mar 2017  路  4Comments  路  Source: edvin/tornadofx

When I use gridpane layout with a row within two or more nodes, the gridpaneConstrains will never work correctly if I set one node (not the last one) using (columnSpan = 2), If I do this, the 2-columns-span node will be covered by the next node in the same row, even though I set all the nodes with correct columnSpan, columnIndex. However, I use pure JavaFx code it will turn all right, so what's wrong with my code below?

override val root = gridpane {
row {
button("Button").gridpaneConstraints { columnRowIndex(0, 0); columnSpan = 2 }
button("Another One").gridpaneConstraints { columnRowIndex(2, 0); columnSpan = 1 }
}
}

And, the code below will work correctly:

val parent = GridPane()
init
{
parent.add(Button("Button"), 0, 0, 2, 1)
parent.add(Button("Another One"), 2, 0, 1, 1)
}
override val root = parent

Thanks for response!

Most helpful comment

Does a syntax like this help?

`class GridColspanFragment : Fragment() {

override val root = gridpane {

    padding = Insets(10.0)
    hgap = 4.0
    vgap = 4.0

    row {
        add(
            rectangle(0.0, 0.0, 80.0, 40.0) {
                fill = Color.RED

            },
            0, 0, 2, 1
        )

        add(
            rectangle(0.0, 0.0, 40.0, 40.0) {
                fill = Color.GREEN
            },
            2, 0, 1, 1
        )
    }
    row {
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.PURPLE
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.BLACK
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.GRAY
        }
    }
    row {
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.PINK
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.YELLOW
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.ORANGE
        }
    }
}

}`

All 4 comments

We have a PR that involves many improvements to GridPane, along with a fix for this issue:

https://github.com/edvin/tornadofx/pull/273/files

We're working on evaluating it and will probably merge it within a couple of days :)

OK, I will wait and update in my project. Thanks.

Does a syntax like this help?

`class GridColspanFragment : Fragment() {

override val root = gridpane {

    padding = Insets(10.0)
    hgap = 4.0
    vgap = 4.0

    row {
        add(
            rectangle(0.0, 0.0, 80.0, 40.0) {
                fill = Color.RED

            },
            0, 0, 2, 1
        )

        add(
            rectangle(0.0, 0.0, 40.0, 40.0) {
                fill = Color.GREEN
            },
            2, 0, 1, 1
        )
    }
    row {
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.PURPLE
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.BLACK
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.GRAY
        }
    }
    row {
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.PINK
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.YELLOW
        }
        rectangle(0.0, 0.0, 40.0, 40.0) {
            fill = Color.ORANGE
        }
    }
}

}`

@bekwam thanks, that really works for me, but after some try I have already gave it up and return to use the form layout instead, for my some complex components, ready hard for me to control in a gridpane. Anyway, thanks very much for your help!

Was this page helpful?
0 / 5 - 0 ratings