2 Replies Latest reply on Mar 16, 2013 12:55 AM by shakir.gusaroff

    Treeview and horizontal  scroll bars

      I have a treeview control and when I expand the nodes on the tree so that they exceed the width of the area allowed the treeview. I do not get a horizontal scroll bar, instead the labels for my nodes are truncated so that they fit within the width allowed for the treeview. How do I get the horizontal scroll bar to appear.
        • 1. Re: Treeview and horizontal  scroll bars
          You need to use a ScrollPane.


          Also check out the fitToWidth and fitToHeight methods of ScrollPane.
          • 2. Re: Treeview and horizontal  scroll bars
            Hi. If you put the tree inside an HBox or VBox, horizontal scrollbar or vertical scrollbar are added automatically if the width or height exceed
            the area allowed for the tree, but it does not happen with all layouts. For example if a tree is inside a FlowPane layout container, the horizontal
            scrollbar is not added if the width exceeds the allowed area.

            If you add the following binds the horizontal scrollbar will be added.
            Here is an example.
              import java.util.Set;
            import javafx.application.Application;
            import javafx.event.ActionEvent;
            import javafx.event.Event;
            import javafx.event.EventHandler;
            import javafx.scene.Group;
            import javafx.scene.Node;
            import javafx.scene.Scene;
            import javafx.scene.control.TreeItem;
            import javafx.scene.control.TreeView;
            import javafx.scene.image.Image;
            import javafx.scene.image.ImageView;
            import javafx.scene.input.ScrollEvent;
            import javafx.scene.layout.BorderPane;
            import javafx.scene.layout.FlowPane;
            import javafx.scene.layout.HBox;
            import javafx.scene.layout.StackPane;
            import javafx.scene.layout.VBox;
            import javafx.stage.Stage;
            public class TreeS extends Application {
                 public static void main(String[] args) {
                public void start(Stage primaryStage) {
                    primaryStage.setTitle("Tree View Sample");        
                    TreeItem<String> rootItem = new TreeItem<String> ("Inbox");
                    for (int i = 1; i < 106; i++) {
                        TreeItem<String> item = new TreeItem<String> ("Messageccccccccccccccccccccccccccccccccccccccccccccccccend" + i);            
                    TreeView<String> tree = new TreeView<String> (rootItem);        
                    FlowPane root = new FlowPane();
                    Scene scene = new Scene(root, 300, 250);