ComponentPeer setTitle not working

Hello everyone!
A quick one I hope…

I want an audio settings component called ‘audioSetupComp’ to Open in a new window and I have this so far:

audioSetupComp.setOpaque(true);
                
        audioSetupComp.addToDesktop(ComponentPeer::windowAppearsOnTaskbar | 
 ComponentPeer::windowHasCloseButton | ComponentPeer::windowHasTitleBar | ComponentPeer::windowIsTemporary);
        //audioSetupComp.addToDesktop(ComponentPeer::ComponentPeer);
        //audioSetupComp.setTitle("Audio Settings");
        audioSetupComp.centreWithSize (600, 400);
        //audioSetupComp.setSize (600, 400);
        
        audioSetupComp.setVisible(true);

Two Issues:

  1. There is a close button on the window but it does not close the window
  2. Using setTitle() gives the error Error C2039 ‘setTitle’: is not a member of ‘juce::AudioDeviceSelectorComponent’

Any help would be most appreciated…

For issue #1, when you add a Component to the desktop using addToDesktop(), the close button ends up triggering the component’s userTriedToCloseWindow() method. I guess this method isn’t implemented by the AudioDeviceSelectorComponent class, so you’d need to create your own subclass that implements this method to remove the selector component.

The issue for #2 is that you are trying to call a ComponentPeer method on a Component object. You need to get the peer using Component::getPeer():

if (auto* peer = audioSetupComp.getPeer())
    peer->setTitle ("Audio Settings");

Although, if you’re creating a plug-in you should be aware that it’s highly inadvisable to create multiple windows!

1 Like