Search code examples
javafx-2fxmlseparator

Is it possible to add a separator in a javafx choicebox in FXML?


This document describes how to add a separator to a javafx 2 choicebox by code: http://docs.oracle.com/javafx/2/ui_controls/choice-box.htm

I would like to achieve the same using a FXML layout. Any ideas?


Solution

  • .fxml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.scene.control.*?>
    <?import javafx.scene.layout.HBox?>
    <?import java.lang.*?>
    
    <HBox xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
      <ChoiceBox>
        <String fx:value="Item 1" />
        <String fx:value="Item 2" />
        <Separator />
        <String fx:value="Item 3" />
      </ChoiceBox>
    </HBox>
    

    Don't forget to import the correct Class. With importing the correct classpath you can include any class and try to display it, even your self-made. Just open the FXML in your SceneBuilder and use Preview to see it in action without building a custom fxml loader for it.

    seperated choices