FileBrowserComponent issues with setFileName()

Hi there,

I have a FileBrowserComponent in a TabbedComponent which is in a settings Component that can be shown/hidden (which is implemented by entirely creating and deleting the component on a button click). Everytime I want to open the FileBrowserComponent through the settings button, I want the filename box to display the current preset name and then also have the corresponding file selected in the browser. I am currently doing this by calling setFileName() in TabbedComponent::currentTabChanged(). Now this all works perfectly when switching between tabs, but it is broken when initially instantiating the settings component (where the FileBrowser is the initial tab displayed). The preset name shows up in the filename box OK but the corresponding file does not get selected in the browser.

I think I know the problem (but not too sure): it seems that currentTabChanged() completes execution before the child FileBrowserComponent completes populating its ListBox. I am assuming this because when I step through, I find that totalItems is 0 when ListBox::selectRowInternal() is called (up the stack from setFileName()). In my specific case, “row” is 3, so the condition isPositiveAndBelow(row, totalItems) results in calling deselectAllRows().

Where can I place this setFileName() call at a time when the ListBox is guaranteed to finish its async task of populating the FileBrowser with files? I can’t see how any of the allowed virtual functions (FileBrowserListener) provide for this. Do I need to build my own FileBrowserComponent for this ?

Many thanks for the help,
Ian.

You could just call setFileName() after a short period of time using Timer::callAfterDelay().