Selecting an item in a tree

I have a feeling I’m missing something very simple here - hope someone can point me in the right direction.

I have created a tree which uses a FilesystemContainer as its data source. I create the tree like this:

filesystemContainer = new FilesystemContainer(new File(app.getRootPlaylistDir()));
tree = new Tree(null,filesystemContainer);

At some point, I want to create a new file in the filesystem, and add it to the tree. This works. However, when I create the file, I do it by selecting the parent directory, and then adding the file to the file system. I would like to change the selection at that point to be the new file.

So for example, if the tree looks like:

and directory ‘cccc’ is selected and I add file ‘newFile’, the tree looks like

Which is correct, but I want newFile to actually be selected. How do I force that?

My code in this area looks like this, but it does not do anything except repaint the tree with the new entry - nothing is showing selected…

____fw = new FileWriter(fullPath);
____fw.write(“Id=99999\n”); // Dummy id

Thanks in advance,


The item IDs in a FilesystemContainer are File objects, not paths. You need to use the File object associated with the file in the setValue().

Notice that you can’t just create a new File object with the same path, that is, “tree.setValue(new File(fullPath))”, as that object would not be the same as is in the container.

You probably need to iterate over the item IDs (which are File object) of the files in the container to find the correct item ID, and then use that to set the selection.

Got it - thanks very much - that should do it…