Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

ScrollPane: issue #1298

Open
DarioArena87 opened this issue Nov 29, 2020 · 3 comments
Open

ScrollPane: issue #1298

DarioArena87 opened this issue Nov 29, 2020 · 3 comments

Comments

@DarioArena87
Copy link

Hi, it seems that when a scrollpane has some children that can be hidden/shown based on some property only the last child is considered.
Example code:

package com.example.view

import javafx.scene.control.ToggleGroup
import javafx.scene.paint.Color
import tornadofx.*

class MainView : View("Hello TornadoFX") {

    private val toggleGroup = ToggleGroup()

    private val visibleComponent = 1.toProperty()

    init {
        visibleComponent.bind(toggleGroup.selectedValueProperty())
    }

    override val root = vbox {
        vbox {
            radiobutton("None", toggleGroup, 0)
            radiobutton("First", toggleGroup, 1)
            radiobutton("Second", toggleGroup,  2)
            radiobutton("Third", toggleGroup,  3)
        }

        scrollpane {
            prefHeight = 500.0

            vbox {
                visibleWhen(visibleComponent.isEqualTo(1))
                prefHeight = 600.0
                label("First Component")
                style {
                    borderColor += box(Color.DARKBLUE)
                    backgroundColor += Color.BLUE
                }
            }

            vbox {
                visibleWhen(visibleComponent.isEqualTo(2))
                prefHeight = 400.0
                label("Second Component")
                style {
                    borderColor += box(Color.DARKGREEN)
                    backgroundColor += Color.GREEN
                }
            }

            vbox {
                visibleWhen(visibleComponent.isEqualTo(3))
                prefHeight = 500.0
                label("Third Component")
                style {
                    borderColor += box(Color.DARKSLATEGRAY)
                    backgroundColor += Color.DIMGRAY
                }
            }
        }
    }
}

If you run this example i'd expect that the first component is visibile and then, based on the radiobutton that i select, the appropriate component is shown but all seems to work only for the last child of the scrollpane.
I'm not really an expert in kotlin (i usually program in plain java or groovy) and i don't have a lot of experience with JavaFX either so i don't know if i'm doing something wrong but maybe this is a bug in how the children gets added to the scrollpane itself

@SKeeneCode
Copy link

SKeeneCode commented Dec 1, 2020

It works for me when you wrap your three vboxs in a parent container like a vbox.

Scrollpane is intended to wrap a single node or layout, so when you keep adding vboxes it is just replacing what was there. This is probably done by repeated calls to a ScrollPanes setContent method. This also explains why only your last vbox is working, because it has replaced whatever was there before.

        scrollpane {
            prefHeight = 500.0
            vbox {
                vbox {  }
                vbox {  }
                vbox {  }
                }
            }
        }

@DarioArena87
Copy link
Author

You are right, i also tried encapsulating content in a vbox and it worked. If this is the intended use of scrollpane maybe it's ok but maybe it will be a nice improvement if TornadoFX handles this for the user (perhaps in an optional way)

@SchweinchenFuntik
Copy link
Contributor

SchweinchenFuntik commented Dec 3, 2020

can better use

stackpane { // vbox
    vbox {  }
    vbox {  }
    vbox {  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants