2

In Javafx the DisclosureNode of Treeview is on left by default. How can I I place the Disclosure Node to Right (float right)..?? Any Help would be appreciated.

Vikas Singh
  • 175
  • 5
  • 19

1 Answers1

1

You only need to set the Node Orientation to get a right to left behaviour. But be aware of, that all childrens of this TreeView will inherit the orientation as a default.

import javafx.application.Application;
import javafx.geometry.NodeOrientation;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class TreeViewRightLeft extends Application {

    @Override
    public void start(Stage primaryStage) {
        TreeItem<String> item = new TreeItem<>("Root Node");
        item.setExpanded(true);
        item.getChildren().addAll(
                new TreeItem<>("Item 1"),
                new TreeItem<>("Item 2"),
                new TreeItem<>("Item 3")
        );
        TreeView<String> treeView = new TreeView<>(item);

        // Here you can select the orientation.
        treeView.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);

        BorderPane root = new BorderPane(treeView);
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("TreeView");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Right to Left

App

Left to Right (default)

AppDefault

aw-think
  • 4,723
  • 2
  • 21
  • 42