문제

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?

도움이 되었습니까?

해결책

.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

다른 팁

This should do it. Replace the "Items" with your own content. Also, take a look at the FXML reference found here for more information on using FXML.

<ChoiceBox>
  <items>
    <FXCollections fx:factory="observableArrayList">
      <String fx:value="Item 1" />
      <String fx:value="Item 2" />
      <Separator fx:id="separator"/>
      <String fx:value="Item 3" />
    </FXCollections>
  </items>
</ChoiceBox>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top