# How do you minimize?

**URL:** <https://forum.juce.com/t/how-do-you-minimize/66>\
**Category:** General JUCE discussion\
**Created:** [September 6, 2004, 1:39am UTC](https://forum.juce.com/t/how-do-you-minimize/66 "2004-09-06T01:39:37Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![valley](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@valley](https://forum.juce.com/u/valley)\
**Post date:** [September 6, 2004, 11:57pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/21 "2004-09-06T23:57:07Z")

</div>

ahhh, I see what you mean.

You may well be right then. That’s a Jules question…

Feel free to fix uit if you can though. 😉

---

<div class="post-metadata">

**Author:** ![ModuLR](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@ModuLR](https://forum.juce.com/u/ModuLR)\
**Post date:** [September 7, 2004, 1:21am UTC](https://forum.juce.com/t/how-do-you-minimize/66/22 "2004-09-07T01:21:47Z")

</div>

Oh well, heres to officially to sucking up another day… of which I basically got not one step closer to accomplishing anything. :shock:

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 7, 2004, 8:31am UTC](https://forum.juce.com/t/how-do-you-minimize/66/23 "2004-09-07T08:31:19Z")

</div>

Components just stay wherever you put them, and in the code above it doesn’t look like you’re even giving them any sizes or positions at all, so no wonder they don’t appear.

The way to do it is to create and add them to the parent comp in the constructor, then have a resized() method that repositions all the child components each time the window is resized.

And if you want a full-screen window, don’t just set it to the size of the desktop - use NativeDesktopWindow::setFullScreen, which copes with multiple monitors, screen resizing, taskbars, etc

---

<div class="post-metadata">

**Author:** ![ModuLR](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@ModuLR](https://forum.juce.com/u/ModuLR)\
**Post date:** [September 7, 2004, 5:13pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/24 "2004-09-07T17:13:09Z")

</div>

but the position and size is set in the titlebar constructor as such…

[code]ApplicationTitleBar::ApplicationTitleBar()  
: Component (T(“Title Bar”))  
{  
setBounds (0,0, getParentWidth(),21);

addAndMakeVisible (minimizeButton = new TextButton (  
T("-"), Colours::black, Colour(0xFF88889F), Colour(0xFF222228),  
T(“Minimize”)));  
minimizeButton-\>addActionListener (this);  
minimizeButton-\>setBounds(getParentWidth()-42,0,20,20);  
minimizeButton-\>setName(“MinimizeButton”);

addAndMakeVisible (closeButton = new TextButton (  
T(“X”), Colours::black, Colour(0xFF88889F), Colour(0xFF222228),  
T(“Close”)));  
closeButton-\>addActionListener (this);  
closeButton-\>setBounds(getParentWidth()-21,0,20,20);  
closeButton-\>setName(“CloseButton”);

// add application buttons  
}[/code]

so why is it that the title bar doesn’t appear if the parent is manually set to 1024x768 upon instancing in the first place? The TitleBar constructor seems to ignore the getparentwidth() and simply use the desktop.

Sorry if I’m not making sense… I’m just trying to understand. The way valley wrote this makes sense to me… and I don’t understand why it doesn’t work. I would think no matter what I set the mainwindow too… the buttons will adjust to the size of the window when it is instanced in the first place. I’m not talking about resizing here… just the initialization.

---

<div class="post-metadata">

**Author:** ![valley](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@valley](https://forum.juce.com/u/valley)\
**Post date:** [September 7, 2004, 5:57pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/25 "2004-09-07T17:57:41Z")

</div>

I wouldn’t make the mistake of assuming my stuff is right.

I barely had chance to glance at the JUCE docs this weekend - I was mostly coding and posting in between plastering/sanding sessions. 😉

Is my use of getParentWidth correct?

I’m assuming it gives the parent container (component), but is is possible it gives for example the screen, in which case this code would not work if you sized your base window compent smaller than your desktop.

I never tested that, as I was using the NativeDesktopWindow::setFullScreen method to set the initial window size.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 7, 2004, 6:16pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/26 "2004-09-07T18:16:58Z")

</div>

RTFM lads - this is the help for getParentWidth()

```
/** Returns the width of the component's parent.

    If the component has no parent (i.e. if it's on the desktop), this will return
    the width of the screen.
*/

```

---

<div class="post-metadata">

**Author:** ![valley](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@valley](https://forum.juce.com/u/valley)\
**Post date:** [September 7, 2004, 6:35pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/27 "2004-09-07T18:35:57Z")

</div>

OK, I think I know what I did wrong Mod.

I’m guessing that the addAndMakeVisible creates the child _before_ taking ownership of it, so probably at constructor time the child has no parent, so getParentWidth() will return the desktop size.

That code should be changed such that the size is set _after_ the constructor has finished. Don’t think of this is a Delphi setParent/setSize way where everything can be donme in one pass from inside the constructor.

What this means is that each component layer needs a resize handler for its’ child components.

IE

MainForm  
createChild1  
createChild2  
mainResizeHandler

Child1  
createSubChild1  
createSubChild2  
createSubChild3  
child1ResizeHandler

etc…

---

<div class="post-metadata">

**Author:** ![SigmaDeltaRob](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@SigmaDeltaRob](https://forum.juce.com/u/SigmaDeltaRob)\
**Post date:** [September 7, 2004, 11:19pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/28 "2004-09-07T23:19:45Z")

</div>

Hey valley, I think it makes more sense for this project to be in Juce/Projects/SampleEditor.

you seem to have it in /Juce

Think we could change that? 🙂

---

<div class="post-metadata">

**Author:** ![SigmaDeltaRob](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@SigmaDeltaRob](https://forum.juce.com/u/SigmaDeltaRob)\
**Post date:** [September 7, 2004, 11:57pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/29 "2004-09-07T23:57:07Z")

</div>

This is definetly a hack I think…

But if you toss this in, you get the window set properly after un-minimizing it.

```auto
void ApplicationMainWindow::minimisationStateChanged (bool isNowMinimised)
{
	if (isNowMinimised == 0)
	{
		repaint(0, 0, getParentHeight(), getParentWidth());
	}
}
```

Quick fix for now…

Working to see why the children aren’t working (not sure if I even understand the problem yet.

editted: made it a more complete hack 🙂 This cant stay very long! Seems like its gonna cause some weird shit later… there should be a callback for this shit… where is it.

---

<div class="post-metadata">

**Author:** ![ModuLR](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@ModuLR](https://forum.juce.com/u/ModuLR)\
**Post date:** [September 9, 2004, 10:08am UTC](https://forum.juce.com/t/how-do-you-minimize/66/30 "2004-09-09T10:08:59Z")

</div>

so I stayed up trying to figure out the buttons things… and I think I’ve finally come to grips with what’s going it.

It’s as valley and jules hinted, the constructor must finish before you go using getparent(), otherwise it’s it’s not actually a child in the case of the way the SampleEditor mock up was written.

So… I tried something and it worked… (btw, first time I used a debugger and it really helped me see what the hell was going on).

Ignore the hack nature…

`// add title bar
addAndMakeVisible(titleBar = new ApplicationTitleBar(), 0);
titleBar->setBounds (0,0, titleBar->getParentWidth(),21);`

it let’s the constructor create the object, then it sets the size and position afterwards. getParentWidth() will be the correct value… no matter what you size the main window.

the button became a problem because getParantWidth()

```auto

```

was being called in the titlebar constructor. The debugger revealed that the value it was returning was zero, thus 0-42 = no show on the screen.

so just as a test, I pulled the setbounds out… and threw them in resize() inside tittleBar…

`void ApplicationTitleBar::resized()
{
  // place buttons on title bar
  minimizeButton->setBounds(minimizeButton->getParentWidth()-42,0,20,20);
  closeButton->setBounds(closeButton->getParentWidth()-21,0,20,20);
}`

now it works, change the static size and the buttons follow… dunno if that’s proper… but it’s getting called after the contructor… thus the buttons being fed the proper widths of their parent.

Enuf geeking out tonight… C++ makes my brain hurt… just had to discuss my revelation before hitting the bed. Lots to learn with this c++ biz…

:roll: 😉

---

<div class="post-metadata">

**Author:** ![ModuLR](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@ModuLR](https://forum.juce.com/u/ModuLR)\
**Post date:** [September 9, 2004, 5:04pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/31 "2004-09-09T17:04:46Z")

</div>

ARGH! Now it places everything right, but the buttons are all sluggish now! WTF?! :shock: :? :evil:

---

<div class="post-metadata">

**Author:** ![SigmaDeltaRob](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@SigmaDeltaRob](https://forum.juce.com/u/SigmaDeltaRob)\
**Post date:** [September 9, 2004, 5:33pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/32 "2004-09-09T17:33:51Z")

</div>

too bad Im taking a break today… you better not fix it before I do! lol 🙂

---

<div class="post-metadata">

**Author:** ![ModuLR](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@ModuLR](https://forum.juce.com/u/ModuLR)\
**Post date:** [September 9, 2004, 5:38pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/33 "2004-09-09T17:38:19Z")

</div>

Hah! it’s because I was in debug mode! Okee righteous! So the buttons are placed correctly, now for the resize… muahahah! :twisted:

---

<div class="post-metadata">

**Author:** ![SigmaDeltaRob](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@SigmaDeltaRob](https://forum.juce.com/u/SigmaDeltaRob)\
**Post date:** [September 9, 2004, 5:46pm UTC](https://forum.juce.com/t/how-do-you-minimize/66/34 "2004-09-09T17:46:08Z")

</div>

get on aim fool.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:51am UTC](https://forum.juce.com/t/how-do-you-minimize/66/35 "2017-05-12T09:51:14Z")

</div>

Closed on May 12, 2017, 9:51am UTC



[Previous page](https://forum.juce.com/t/how-do-you-minimize/66.md?page=1)
