Steve
Steve

Reputation: 4691

SplitMenuButton in FXML

I'd like to create a SplitMenuButton using FXML. I can find documentation on how to do it in java, but not in the xml file. How can I do this?

Additionally, if there's a good source for FXML documentation, please point me to it.

Upvotes: 0

Views: 541

Answers (1)

James_D
James_D

Reputation: 209418

You can do

<SplitMenuButton fx:id="smButton" text="Text">
    <items>
        <MenuItem text="Choice 1" onAction="#action1" />
        <MenuItem text="Choice 2" onAction="#action2" />
    </items>
</SplitMenuButton>

There is an "Introduction to FXML" document that describes how FXML works in general. However, for use cases such as this, you really just need the Javadocs. Elements beginning with a capital correspond to class names, i.e. they are an instruction to instantiate that class. Attributes correspond to properties, so

<SplitMenuButton fx:id="smButton" text="Text"/>

essentially means

SplitMenuButton smButton = new SplitMenuButton();
smButton.setText("Text");

The only tricky thing here is the <items> element, which is a Read Only List Property as described in the afore-mentioned Introduction to FXML.

Upvotes: 2

Related Questions