setContentComponent is deprecated. What should I do?


#1

…Hi, what should I do to add a content component to a newly created window?
I’ve got a window but I can’t add a normal component, what is the best way to do that?
Thanks,
Dave.

class DeviceWindow : public DocumentWindow
{
public:
	DeviceWindow(const String& name, Colour backgroundColour, int buttonsNeeded, AudioDeviceManager &manager)
		: DocumentWindow(name, backgroundColour, buttonsNeeded)
	{

The following is  illegal, because my windows has no content component:
//		addAndMakeVisible(audioSetupComp = new AudioDeviceSelectorComponent(manager, 0, 256, 0, 256, true, true, true, false));

	}

	void closeButtonPressed()
	{
		delete this;
	}

private:
	ScopedPointer<AudioDeviceSelectorComponent> audioSetupComp;
	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DeviceWindow)
};

#2

OK, I’ve copied the way Main.cpp and MainComponent works and I got this-
It seems to work OK. Although I suspect there’s a better way to grab the device manager other than passing it down to my window component.

Component *makeDeviceContent(AudioDeviceManager &);

class DeviceWindow	: public DocumentWindow
{
public:
	DeviceWindow(const String& name, Colour backgroundColour, int buttonsNeeded, AudioDeviceManager &manager)
		: DocumentWindow(name, backgroundColour, buttonsNeeded)
	{
		setContentOwned(makeDeviceContent(manager), true);
	}

	void closeButtonPressed()
	{
		delete this;				    
	}

private:

	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DeviceWindow)
};