By setting
the orientation to vertical, you can create vertical separators (Horizontal is
the default orientation of separator).
Example 1
Separator
separator1 = new Separator(Orientation.VERTICAL);
Example 2
Separator
separator2 = new Separator();
separator2.setOrientation(Orientation.VERTICAL);
Find the
below working application.
demo.css
.separator{ -fx-border-color: #ff0000; -fx-border-width: 2; }
SeparatorApp.java
package com.sample.demos; import java.io.File; import javafx.application.Application; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.Separator; import javafx.scene.layout.HBox; import javafx.scene.text.Font; import javafx.stage.Stage; public class SeparatorApp extends Application { private static String cssFilePath = "C:\\Users\\krishna\\Documents\\Study\\javaFX\\demo.css"; @Override public void start(Stage primaryStage) throws Exception { final HBox hBox = new HBox(); final Font font = new Font("Arial", 20); final String[] days = new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; final Label[] labels = new Label[days.length]; for (int i = 0; i < days.length; i++) { labels[i] = new Label(days[i]); labels[i].setFont(font); } Separator separator1 = new Separator(Orientation.VERTICAL); separator1.getStyleClass().add("separator"); separator1.setMaxHeight(50); Separator separator2 = new Separator(); separator2.setOrientation(Orientation.VERTICAL); separator2.getStyleClass().add("separator"); separator2.setMaxHeight(50); hBox.getChildren().addAll(labels); hBox.getChildren().add(3, separator1); hBox.getChildren().add(6, separator2); hBox.setSpacing(5); Scene scene = new Scene(hBox); scene.getStylesheets().add(new File(cssFilePath).toURI().toURL().toExternalForm()); primaryStage.setScene(scene); primaryStage.setTitle("Separator widger Example"); primaryStage.setWidth(900); primaryStage.setHeight(500); primaryStage.show(); } }
TestFX.java
package com.sample.demos; import javafx.application.Application; public class TestFX { public static void main(String args[]) { Application.launch(SeparatorApp.class, args); } }
No comments:
Post a Comment