【问题标题】:Java-gnome (GTK): why is my TreeView displayed empty?Java-gnome (GTK):为什么我的 TreeView 显示为空?
【发布时间】:2014-04-02 22:03:43
【问题描述】:

我正在尝试在 GtkTreeView 中显示字符串列表(文件名,要学究)。我正在创建一个列并尝试用 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);

程序编译并运行没有错误,但列表显示为空。有人可以帮我找出错误吗?

【问题讨论】:

    标签: java gtk gnome gtktreeview


    【解决方案1】:

    添加imageList.set_model (listStore),它实际上将您的视图与模型相关联。这是必需的,否则视图将保持空白,因为它没有模型关联,除非您在构建器文件中指定它,我现在只能猜测。

    【讨论】:

    • 是的,这就是解决方案!我忘了这样做是因为我遵循的教程没有使用 Builder:模型已链接实例化视图:new TreeView(model);谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多