# DialogWindow and ContentOwned

**URL:** <https://forum.juce.com/t/dialogwindow-and-contentowned/12163>\
**Category:** General JUCE discussion\
**Created:** [January 8, 2014, 10:51am UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163 "2014-01-08T10:51:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvaz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@pvaz](https://forum.juce.com/u/pvaz)\
**Post date:** [January 8, 2014, 10:51am UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/1 "2014-01-08T10:51:23Z")

</div>

Hi there,

&nbsp;

Can anyone help me giving me one example on how to use dialog windows and to put inside the dialog windows one component.

And when the component is closed (press a button on the component to close it) the window is closed.

What i've made so far is this:

```
String m; m << "";
DialogWindow::LaunchOptions options;
Label* label = new Label();
label->setText(m, dontSendNotification);
label->setColour(Label::textColourId, Colours::darkgrey);
options.content.setOwned(label);
Rectangle<int> area(0, 0, 378, 407);
options.content->setSize(area.getWidth(), area.getHeight());
options.dialogTitle = "Login Window";
options.dialogBackgroundColour = Colours::darkgrey;
options.componentToCentreAround;
options.escapeKeyTriggersCloseButton = true;
options.useNativeTitleBar = false;
options.resizable = false;

DialogWindow* dw = options.launchAsync();
dw->setContentOwned(showLoginPage(), false);
dw->setTitleBarHeight(0);
dw->setVisible(true);
dw->centreWithSize(378, 407);
```

But the result is that when i press the close button on the component called showLoginPage().

I've got this code from the demo of Juce, but of course it's not the correct way to do it.

Paulo

&nbsp;

---

<div class="post-metadata">

**Author:** ![pvaz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@pvaz](https://forum.juce.com/u/pvaz)\
**Post date:** [January 9, 2014, 9:43pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/2 "2014-01-09T21:43:40Z")

</div>

Hi again,

unfortunally no one give a suggestion, i've found out the way to close it.

On the component, i added this associated with the close button:

```
Component::getParentComponent()->exitModalState(0);
```

But if anyone as a better way to do it, tell ...

Paulo

---

<div class="post-metadata">

**Author:** ![matty](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@matty](https://forum.juce.com/u/matty)\
**Post date:** [January 10, 2014, 5:42am UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/3 "2014-01-10T05:42:14Z")

</div>

The code you've copied from WindowsDemo.cpp of the JUCE demo adds a Label (a Component) to the DialogWindow:

```
DialogWindow::LaunchOptions options;
Label* label = new Label();
label->setText (m, dontSendNotification);
label->setColour (Label::textColourId, Colours::whitesmoke);**options.content.setOwned (label);**
```

Instead of Label, you could add your own component.

Also, from the documentation for launchAsync(), "_When the dialog's close button is clicked, it'll automatically terminate its modal state_..." So you shouldn't need to do this yourself. I'm guessing if you do it the way it's done in WindowsDemo.cpp, you won't need your hack.

---

<div class="post-metadata">

**Author:** ![pvaz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@pvaz](https://forum.juce.com/u/pvaz)\
**Post date:** [January 15, 2014, 7:51pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/4 "2014-01-15T19:51:45Z")

</div>

Hi,

On the DialogWindow that I've created, i have a button that when pressed should close my dialogWindow and open a newComponent.

I have a call to my MainWindow:

```
FrontPageComponent* frontPage = NULL;

if (buttonThatWasClicked == btnExit)
{
//Close Dialog Window
Component::getParentComponent()->exitModalState(0);
} else if (buttonThatWasClicked == btnOk)
{
//Show First Component 
frontPage->showComponentOne();
}
```

in my FrontPageComponent I have this function showComponentOne():

```
void FrontPageComponent::showComponentOne()
{
Component::getCurrentlyModalComponent()->exitModalState(0);
addAndMakeVisible(showFirstComponent());
if (showFirstComponent() != nullptr)
{
showFirstComponent()->setBounds(0,0,1024,768);
}
}
```

What is happening is when i press the button on the DialogWindow that calls the showComponentOne and nothing happens, DialogWindow is closed but my component is not shown.

What am I doing wrong ?

How can I position this component to be on my DocumentWindow.

I can use a button on my FrontPageComponent that opens the new component called FirstComponent without any problem the same way:

```
addAndMakeVisible(showFirstComponent());
if (showFirstComponent() != nullptr)
{
showFirstComponent()->setBounds(0,0,1024,768);
}
```

But opening a DialogWindow and from the DialogWindow calling this, cannot !

Paulo

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [January 15, 2014, 7:57pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/5 "2014-01-15T19:57:00Z")

</div>

You’re way over thinking this… Simply create a new class based on Component, in the main class display the the opaque new class on top of the original class as a child and make it the same size as the parent. It will completely cover the parent and when you close it the parent will be visible.

Rail

---

<div class="post-metadata">

**Author:** ![pvaz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@pvaz](https://forum.juce.com/u/pvaz)\
**Post date:** [January 15, 2014, 8:06pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/6 "2014-01-15T20:06:51Z")

</div>

Hi Rail,

the situation is not related with me hidding the main component, but what I want is that from the DialogWindow to be able to close it and show a diferent Component, not the main.

&nbsp;

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [January 15, 2014, 8:46pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/7 "2014-01-15T20:46:00Z")

</div>

So when the first component closes have the parent create and display the next component class object… The parent is always there and runs the show… The parent doesn’t need to be your main window… It can be a controller class which handles what components you display

Rail

---

<div class="post-metadata">

**Author:** ![pvaz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@pvaz](https://forum.juce.com/u/pvaz)\
**Post date:** [January 15, 2014, 8:51pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/8 "2014-01-15T20:51:00Z")

</div>

On my MainWindow i have this function:

```
void MainWindow::showComponentOne()
{
Component::getCurrentlyModalComponent()->exitModalState(0);
firstComponent = new FirstComponent();
getContentComponent()->addChildComponent(firstComponent, -1);
}
```

that is called from my DialogWindow.

Main purpose is to close the DialogWindow and show a new Component.

But, it gives me this error:

"Unhandled exception at 0x00CCCFBF in JuceDemoTest.exe: 0xC0000005: Access violation reading location 0x00000120."

And takes me to this function:

```
ScopedPointer& operator= (ObjectType* const newObjectToTakePossessionOf)
{
if (object != newObjectToTakePossessionOf)
{
```

What is wrong ?

Paulo

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [January 17, 2014, 7:06pm UTC](https://forum.juce.com/t/dialogwindow-and-contentowned/12163/9 "2014-01-17T19:06:44Z")

</div>

You’re trying to access an object which doesn’t exist… If you look at the this value in the debugger it’ll be NULL

Rail
