简体   繁体   English

Java-gnome(GTK):为什么我的TreeView显示为空?

[英]Java-gnome (GTK): why is my TreeView displayed empty?

I'm trying to display a list of strings (filenames, to be pedant) inside a GtkTreeView. 我正在尝试在GtkTreeView中显示一个字符串列表(文件名,作为学究)。 I'm creating a single column and trying to fill it with a CellRenderText. 我正在创建一个列并试图用CellRenderText填充它。

    //Setup listview
    TreeView imageList = (TreeView)gladeBuilder.getObject("imageListTreeView");
    TreeViewColumn column = imageList.appendColumn();
    DataColumnString imageColumnString = new DataColumnString();

    //Fill listview
    ListStore listStore = new ListStore(new DataColumnString[]{imageColumnString});


    File[] imageFiles = new File("/path/to/files").listFiles();
    // For each file: 
    for (File file : imageFiles) {
        TreeIter row = listStore.appendRow();   //add a row
        listStore.setValue(row, imageColumnString, file.getName());
    }

    CellRendererText cellRendererText = new CellRendererText(column);
    cellRendererText.setText(imageColumnString);

The program compiles and run without errors, but the list is displayed empty. 程序编译并运行没有错误,但列表显示为空。 Someone can help me to find the error(s)? 有人可以帮我找到错误吗?

Add imageList.set_model (listStore) which actually associates your view with the model. 添加imageList.set_model (listStore) ,它实际上将您的视图与模型相关联。 This is required or the view will stay empty as it has no model associate unless you specified it in the builder file which I can only guess at this point. 这是必需的,或者视图将保持为空,因为它没有模型关联,除非您在构建器文件中指定它,我只能在这一点猜测。

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

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