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)?
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.