By
creating a Separator object, you can add separator between elements of
ChoiceBox.
Ex
Separator
SEPARATOR = new Separator();
ChoiceBox<Object>
choiceBox1 = new ChoiceBox<>();
choiceBox1.setItems(FXCollections.observableArrayList("New",
"Open File...", SEPARATOR, "close", "close
all",SEPARATOR, "save", "save as", "save
all"));
Find the
below working application.
package com.sample.demos; import java.io.FileNotFoundException; import java.net.MalformedURLException; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.scene.Scene; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Separator; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class ChoiceBoxApp extends Application { private static final Separator SEPARATOR = new Separator(); @Override public void start(Stage primaryStage) throws FileNotFoundException, MalformedURLException { ChoiceBox<Object> choiceBox1 = new ChoiceBox<>(); choiceBox1.setItems(FXCollections.observableArrayList("New", "Open File...", SEPARATOR, "close", "close all", SEPARATOR, "save", "save as", "save all")); VBox vbox = new VBox(10, choiceBox1); Scene scene = new Scene(vbox, 400, 300); /* Set the scene to primaryStage, and call the show method */ primaryStage.setTitle("JavaFX Choice Box Example"); primaryStage.setScene(scene); primaryStage.show(); } }
TestFX.java
package com.sample.demos; import javafx.application.Application; public class TestFX { public static void main(String args[]) { Application.launch(ChoiceBoxApp.class, args); } }
No comments:
Post a Comment