Skip to content
Brian edited this page Jun 30, 2018 · 6 revisions

Below is an example of how to utilize TornadoFX builders with the JFoenix button. All that is needed is jfxbutton() inside the root. If you would like to style the buttons using CSS, you are able to leverage TornadoFX's type safe css. I have created a JFXStylesheet that contains CSS classes and properties used by JFoenix. If you are new to TornadoFX, please refer to the guide about using type safe CSS. The

import javafx.geometry.Pos
import javafx.scene.paint.Color
import tornadofx.*

class TestApp: App(Main::class, CustomStyles::class) 

class Main : View() {

    override val root = vbox {
        addClass(CustomStyles.container)
        jfxbutton("Flat")
        jfxbutton("Raised").addClass(JFXStylesheet.jfxButtonRaised)
        jfxbutton("Raised w/ Yellow Fill").addClass(CustomStyles.jfxButtonFill)
    }
}

class CustomStyles : JFXStylesheet() {

    companion object {
        val container by cssclass()
        val jfxButtonFill by cssclass()
    }

    init {
        container {
            prefHeight = 300.px
            prefWidth = 400.px
            alignment = Pos.CENTER
            spacing = 20.px
        }

        jfxButton {
            backgroundColor += Color.web("#4059a9")
            textFill = Color.WHITE
            prefWidth = 200.px
            prefHeight = 50.px
        }

        jfxButtonFill {
            jfxRippler {
                jfxRipplerFill.value = Color.YELLOW
            }
        }
    }
}
Clone this wiki locally