简体   繁体   English

JavaFX Treeview WordWrap问题

[英]JavaFX Treeview WordWrap issue

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. 我使用TreeView制作了一个非常简单的UI,但是我找不到如何使文本环绕的方法,以使文本不会消失。 I've tried using CSS but it doesn't make any difference. 我试过使用CSS,但没有任何区别。 If i apply CSS to any other object it works, so i'm pretty sure i've imported the style sheet correctly. 如果我将CSS应用于任何其他对象,则可以正常工作,因此,我很确定自己已正确导入样式表。 As a side note is there a place where all the possible CSS functions are listed? 附带说明一下,是否列出了所有可能的CSS函数? 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 在您的css文件中,您可以添加

.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 您可以在此处找到CSS参考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. 您可以通过查看jfxrt.jar文件中的caspian.css或仅使用Google在互联网上找到它来查看当前设置。

You can also use .setCellFactory to specify how the cells are made. 您也可以使用.setCellFactory来指定单元格的制作方式。 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. 我使用TextFields进行编辑,但我只是将其更改为TextArea,效果也很好,除了按下Enter时出现了一些小问题,但很容易解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM