0

I'm trying to display a list of strings (filenames, to be pedant) inside a GtkTreeView. I'm creating a single column and trying to fill it with a 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)?

penguin86
  • 109
  • 7

1 Answers1

2

Add imageList.set_model (listStore) which actually associates your view with the model. 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.

drahnr
  • 6,782
  • 5
  • 48
  • 75
  • Yes, this is the solution! I forgot to do it because the tutorial I was following didn't use Builder: The model was linked instantiating the view: new TreeView(model); Thank you! – penguin86 Apr 06 '14 at 00:08