How to show different components by selecting a TreeViewItem


#1

Hi,

I like the JUCE just as other users do. I am trying to learn it using the JUCE Demo. I want to have two components on a document window: TreeView and a generic JUCE component. I modified FontAndTextDemo.cpp so that I could replace the ListBox with a TreeView. I have a TreeView on the left and TextEditor on the right. I also learned using the TreeViewDemo.cpp how to add and remove TreeViewItems.

Now, I want to replace the right-hand side TextEditor including sliders below it with a new JUCE component depending on TreeViewItem selected in TreeView on the left-hand side.


| | |
| TreeView | JUCE Component |
| | |
| | |

I seem to be able to achieve this goal in this way:

  1. When one of the following events occur from TreeViewItem,
    virtual void itemClicked (const MouseEvent &e)
    virtual void itemDoubleClicked (const MouseEvent &e)
    virtual void itemSelectionChanged (bool isNowSelected)
    I could use ownerView of TreeViewItem to call a method of TreeView. TreeView would call another method of TreeViewDemo class so that we could delete the current JUCE Component and new another JUCE Component.

The GUI that I want to have is similar to “Preferences” or “Configurations” of a gui program. It is similar to TabbedComponent in that TabbedComponent shows different components depending on different tabs. I want to use TreeView’s TreeViewItem instead of tabs.

I am wondering if there is a good approach for this. I am sure I may be in a wrong track because I just started to learn JUCE.

I will appreciate any help.

Thank you,

Sang Chul


#2

I’d suggest that when you create your treeviewitem objects, you give them a pointer to some sort of high-level component or control object, so that they can call a method to tell it that they’ve been clicked on. Then the control object can change the active component.

I’ve got a similar arrangement in the way that the new jucer has a project tree that lets you select which file to edit, but that’s maybe a bit of a complex example to look at!


#3

Thank you! That would be a nice example.