Search code examples
javajavafxfxmlstatusbarcontrolsfx

Adding buttons in a StatusBar via FXML


How can I add buttons using FXML to ControlsFX StatusBar?

This is how my status bar is created in my fxml:

<StatusBar fx:id="statusBar" onMouseEntered="#openSomething" onMouseExited="#closeSomething"/>

I saw I can add buttons to this status bar but I have no idea how to add buttons to the status bar via FXML. I tried adding buttons via java code and this works fine. Like this:

statusBar.getLeftItems().add(new Button("Info"));

But I want to add the via FXML.


Solution

  • Here is an example of a StatusBar in FXML:

    <StatusBar fx:id="mainStatusBar" text="This is a StatusBar" progress=".314">
        <leftItems>
            <Button text="L Button 1"/>
            <Button text="L Button 2"/>
        </leftItems>
        <rightItems>
            <Button text="R Button"/>
            <ComboBox/>
        </rightItems>
        <graphic>
            <ImageView>
                <Image url="@/icons/sb.png"/>
            </ImageView>
        </graphic>
    </StatusBar>