如何在Javafx中将Treeview DisclosureNode改为正确?

时间:2015-09-22 06:04:12

标签: javafx treeview disclosure

在Javafx中,Treeview的DisclosureNode默认在左侧。如何将Disclosure Node置于右侧(向右浮动).. ?? 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您只需要设置节点方向以获得从右到左的行为。但请注意,此TreeView的所有子项都将继承该方向作为默认值。

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);
    }
}

从右到左

App

从左到右(默认)

AppDefault