I am making a very simple UI using TreeView but I can't find out how to make the text wrap around so that it doesn't go out of view. I've tried using CSS but it doesn't make any difference. If i apply CSS to any other object it works, so i'm pretty sure i've imported the style sheet correctly. As a side note is there a place where all the possible CSS functions are listed? I've always struggled knowing what options i can apply to an object.

  public static TreeView DataTreeView; //this is from my FXML


  public static void TreePopulate(){

    TreeItem<String> rootItem = new TreeItem<String>("Data");

    TreeItem<String> DataNode = new TreeItem<String>("Data about the leaf offset etc");

    //this is the line that goes off screen
    TreeItem<String> DataLeaf = new TreeItem<String>(" lots of data dbabdbwdbawbdawbdbawb ewqeweqwe qweqweqw qeqweqwe "); 


    rootItem.getChildren().add(DataNode);
    DataNode.getChildren().add(DataLeaf);


    DataTreeView.getStyleClass().add("wordwrap");
    DataTreeView.setRoot(rootItem);



}

.wordwrap{
 -fx-wrap-text: true;

}
有帮助吗?

解决方案

In your css file you can add

.tree-cell .label {
    -fx-wrap-text: true;
}

You can find the css reference here http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html

You can see the current settings by looking at caspian.css in your jfxrt.jar file or just using google to find it on the internet.

You can also use .setCellFactory to specify how the cells are made. I use TextFields for editing but I just changed it to TextArea and that works fine as well, except for a little problem with pressing enter but that's easy to fix.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top