简体   繁体   中英

Trying to position Elements in TornadoFX

I wanted to know if it was possible to have multiple smaller panes in the borderpane. Examining the image , the pink rectangle is where I want to add a toolbar. However, I do not know how to place it next to the title. This is what I've tried so far (top section only).

class MainView : View("Dashboard") {
    override val root = borderpane {
        top = hbox {
            val title = label("Dashboard") {
                addClass(Styles.title)

            }
        }

        val toolbar = stackpane {
            label("Toolbar") {
                addClass(Styles.title)
            }
        }

        (top as HBox).alignment = Pos.TOP_CENTER
        (toolbar as StackPane).alignment = Pos.CENTER_RIGHT

It's possible with a stack pane:

override val root = borderpane {
    top = stackpane {
        toolbar {
            region  { // Only needed if you want content on the left side
               hgrow = Priority.SOMETIMES 
            }
            label("Toolbar") {
                addClass(Styles.title)
            }
        }
        label("Dashboard") {
            addClass(Styles.title)
        }
    }
}

Keep in mind that the title and toolbar will overlap if pushed towards each other. And make sure the title is added last in the stack pane!

PS This stackpane method is only if you want your title centered to the window . If you just want it centered in relation to content, then there are many more options. You could even put a borderpane in the top of your borderpane.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM