Changing between Components


Juce Friends,

Hello from Texas. I’m stuck right now on how to delete a component and then have a new component created that is a child of the DocumentWindow. Basically replace a component with a new one in the same DocumentWindow.

This is a login application, and after the user successfully authenticates with credentials, a new Main Menu Component should be created. What happens right now is I don’t know how to delete the Authentication Component, and the Menu Component does get created on top of the Auth Component, but when you maximize the DocumentWindow, the Auth Component is still there in the background, and the new Menu Component doesn’t maximize along with the DocumentWindow. This is because the MainMenu Component is not somehow attached to or a child of the DocumentWindow. Attached is a screen shot showing this and how funny it is.

Any insight greatly appreciated for these questions. I am really lost. I want to know how to replace components easily and have them attached to the same DocumentWindow object.

  1. How do I delete the AuthComponent within the cpp file that is running it?
  2. How do I make sure that the new Menu Component is a child of the DocumentWindow object?

Please help. Here is code for creating Menu Component within the cpp file that is running the Auth Component:
if (result == 1) {
// Authentication success
// We probably should delete the AuthComponent but we don’t know how

            // create menu for user
            MainMenuComponent* themenu;
            themenu = new MainMenuComponent();

            theMainWindow->setName(T("Welcome to LAVA"));

    } else {

            // Auth failed - Alert Window Box display
            AlertWindow::showMessageBox(AlertWindow::NoIcon, T("Authentication failed"),T("Invalid username or password"));


Is DocumentWindow::setContentComponent the thing that you’re looking for? Presumably you just want to set the content to be your log-in page, then when it’s done, you’d change the content to be your new page, and setContentComponent would delete the old one for you…


Thanks, that was just what I was looking for. One more question - is there a function that will automatically maximize the component / documentwindow so that it takes up all of the space on the desktop?


Never mind Julian. I found the ResizableWindow::setFullScreen() function. Thanks for all of your help friends.

All the best,