# AlertWindow and DialogWindow won't scale and center after setGlobalScaleFactor or when JUCE\_WIN\_PER\_MONITOR\_DPI\_AWARE disabled

**URL:** <https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785>\
**Category:** General JUCE discussion\
**Created:** [September 11, 2021, 2:22pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785 "2021-09-11T14:22:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexrdsp](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/alexrdsp/32/5912_2.png) [@alexrdsp](https://forum.juce.com/u/alexrdsp)\
**Post date:** [September 11, 2021, 2:22pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/1 "2021-09-11T14:22:36Z")

</div>

AlertWindow and DialogWindow won’t scale and center after setGlobalScaleFactor or when JUCE\_WIN\_PER\_MONITOR\_DPI\_AWARE disabled.

i’m using juce 6.1.1 on windows.

I created a new project (standalone audio application) to reproduce.

MainComponent constructor

```
    addAndMakeVisible(m_btn);
    m_btn.setButtonText("OPEN DIALOG");
    m_btn.onClick = [this] {

    juce::DialogWindow::LaunchOptions o;      
    o.content.setOwned(new TestComponent());
    o.content->setSize(460, 300);
    o.dialogTitle = "Dialog test";
    o.dialogBackgroundColour = o.content->getLookAndFeel().findColour(juce::DocumentWindow::backgroundColourId);
    o.escapeKeyTriggersCloseButton = true;
    o.useNativeTitleBar = false;
    o.resizable = false;
    o.componentToCentreAround = this;
    
    o.launchAsync();

};

```

Result : dialog is centered.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/1/1ca85b9bfe851f0aec9067538ba54e695f36d100.png)

Now in the app constructor i add :  
` juce::Desktop::getInstance().setGlobalScaleFactor(1.5f);`

Result:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/1/14c896ea20891a5eb96e72c7cdce7da16cfc6963.png)

Now JUCE\_WIN\_PER\_MONITOR\_DPI\_AWARE is disabled and setGlobalScaleFactor removed.

Result:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/a/a5c20da65f966e1155ad0b0c8c65ff3612ddda4b.png)

Am i doing something wrong ?

---

<div class="post-metadata">

**Author:** ![alexrdsp](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/alexrdsp/32/5912_2.png) [@alexrdsp](https://forum.juce.com/u/alexrdsp)\
**Post date:** [September 22, 2021, 11:04pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/2 "2021-09-22T23:04:12Z")

</div>

Looks like when JUCE\_WIN\_PER\_MONITOR\_DPI\_AWARE is disabled ,  
Desktop::getInstance().getGlobalScaleFactor() returns the system set scale which in my case is 1.25 (125%).  
However AlertWindow and DefaultDialogWindow desktopScale member get set to 1.0f.

Those patches seem to resolve the issue.

juce\_AlertWindow.cpp (Line : 39)

```auto
AlertWindow::AlertWindow (const String& title,
                          const String& message,
                          MessageBoxIconType iconType,
                          Component* comp)
   : TopLevelWindow (title, true),
     alertIconType (iconType),
     associatedComponent (comp),
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
     desktopScale (comp != nullptr ? Component::getApproximateScaleFactorForComponent (comp) : 1.0f)
#else
    desktopScale (Desktop::getInstance().getGlobalScaleFactor())

#endif
{
    setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());

    accessibleMessageLabel.setColour (Label::textColourId, Colours::transparentBlack);
    addAndMakeVisible (accessibleMessageLabel);

    if (message.isEmpty())
        text = " "; // to force an update if the message is empty

    setMessage (message);

    AlertWindow::lookAndFeelChanged();
    constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
}

```

juce\_DialogWindow.cpp (Line : 79)

```auto
  DefaultDialogWindow (LaunchOptions& options)
        : DialogWindow (options.dialogTitle, options.dialogBackgroundColour,
                        options.escapeKeyTriggersCloseButton, true,
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
                        options.componentToCentreAround != nullptr
                            ? Component::getApproximateScaleFactorForComponent (options.componentToCentreAround)
                            : 1.0f)
#else
        Desktop::getInstance().getGlobalScaleFactor())
#endif
    {
        setUsingNativeTitleBar (options.useNativeTitleBar);
        setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());

        if (options.content.willDeleteObject())
            setContentOwned (options.content.release(), true);
        else
            setContentNonOwned (options.content.release(), true);

        centreAroundComponent (options.componentToCentreAround, getWidth(), getHeight());
        setResizable (options.resizable, options.useBottomRightCornerResizer);
    }

```

juce\_TopLevelWindow.cpp (Line : 290)

```auto
void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
{
    if (c == nullptr)
        c = TopLevelWindow::getActiveTopLevelWindow();

    if (c == nullptr || c->getBounds().isEmpty())
    {
        centreWithSize (width, height);
    }
    else
    {
#if JUCE_WIN_PER_MONITOR_DPI_AWARE
        auto targetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre()) / getDesktopScaleFactor();
#else
        auto targetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre());

#endif
        auto parentArea = c->getParentMonitorArea();

        if (auto* parent = getParentComponent())
        {
            targetCentre = parent->getLocalPoint (nullptr, targetCentre);
            parentArea = parent->getLocalBounds();
        }

        setBounds (Rectangle<int> (targetCentre.x - width / 2,
                                   targetCentre.y - height / 2,
                                   width, height)
                     .constrainedWithin (parentArea.reduced (12, 12)));
    }
}

```

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [September 29, 2021, 2:00pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/3 "2021-09-29T14:00:45Z")

</div>

Thanks for reporting. I’ve pushed a fix for this to the `develop` branch here:

> <https://github.com/juce-framework/JUCE/commit/8d75a7a40055f5164c7ce324ade05370758f2913>

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [October 10, 2021, 4:12pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/4 "2021-10-10T16:12:12Z")

</div>

while this commit seems to fix standalone exe’s on Windows,  
I still experience a similar issue with vst3 and vst2 plugins.

The following is a juce AudioPluginDemo with a new button which toggles the juce desktop scaling factor between 1.0 and 1.5 and another one showing a simple alert. The alertwindow appears to scale somewhat, yet looks still too small to me in both cases?

 ![scalingbug](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/743e039c96ed29705bb4a8b213ed28c70f5f29e1.png)

note this is the latest develop branch of today

I’m running Windows 10 on a macbook pro with retina display. The Windows HDPI desktop scaling factor is set to 200%. And indeed the alert seems to be about half the size we would expect?

PS: PM me if you’d like the code

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [October 11, 2021, 8:57am UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/5 "2021-10-11T08:57:19Z")

</div>

In a plug-in you’ll need to associate the auxiliarlly desktop window with your editor component since this has a scale factor that has been set by the host, which may not correspond to the desktop scale factor. You can do this via the `associatedComponent` parameter for `AlertWindow`s.

---

<div class="post-metadata">

**Author:** ![calvin](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@calvin](https://forum.juce.com/u/calvin)\
**Post date:** [October 13, 2021, 8:09am UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/6 "2021-10-13T08:09:54Z")

</div>

The problem seem that child windows do not get desktopscale factor. there is a simular thread. here . and the result is [Use font and size from DAW in juce popup menus? - #23 by getdunne](https://forum.juce.com/t/use-font-and-size-from-daw-in-juce-popup-menus/46303/23)

I think it is very usefull that all child windows that are create from a parent window have the same desktop scale factor

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [October 17, 2021, 1:37pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/7 "2021-10-17T13:37:20Z")

</div>

> > You can do this via the `associatedComponent` parameter for `AlertWindow`s.

thanks @ed95, that worked! (could only test now…)

- _associatedComponent_ parameter did the trick for juce::AlertWindow ctor
- also, the _componentToCentreAround_ parameter was needed for juce::DialogWindow::showModalDialog()

---

<div class="post-metadata">

**Author:** ![calvin](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@calvin](https://forum.juce.com/u/calvin)\
**Post date:** [October 18, 2021, 6:51pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/8 "2021-10-18T18:51:02Z")

</div>

Hello  
is it possible to easy add code, that juce is able to open all child windows of a plugin with the current windows desktop scale factor ?. because currently desktop scale-factor does not get propagated to new juce::DocumentWindow based windows created by a JUCE-based plug-in for example additional preference windows or popup menu windows

---

<div class="post-metadata">

**Author:** ![charlifiiiii](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@charlifiiiii](https://forum.juce.com/u/charlifiiiii)\
**Post date:** [November 26, 2024, 9:39am UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/9 "2024-11-26T09:39:53Z")

</div>

I confirm that using Juce 8.0.4, when creating a DocumentWindow from a plugin, the scale factor may not correspond to the GlobalScaleFactor. Using an Affine transform on the DocumentWindow afterwards does not seem to fix the issue (components like textEditor may not display correctly in the window). Any recommandation ? Thanks

---

<div class="post-metadata">

**Author:** ![calvin](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@calvin](https://forum.juce.com/u/calvin)\
**Post date:** [November 26, 2024, 10:28am UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/10 "2024-11-26T10:28:11Z")

</div>

that such a important feature after this many years still not work correct and need pay für juce is really not good.

I have luck and i get money back for unify plugin from developer because scaling not work. the unify developer pay for juce, maybe the juce team is so friendly and give him too some money back, because of bad working scaling features it is possible that many see the demo and not buy or get money back

---

<div class="post-metadata">

**Author:** ![charlifiiiii](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@charlifiiiii](https://forum.juce.com/u/charlifiiiii)\
**Post date:** [December 2, 2024, 3:25pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/11 "2024-12-02T15:25:52Z")

</div>

Can we expect a fix for this issue ? It was experienced on Windows 10. Thx

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [December 2, 2024, 7:55pm UTC](https://forum.juce.com/t/alertwindow-and-dialogwindow-wont-scale-and-center-after-setglobalscalefactor-or-when-juce-win-per-monitor-dpi-aware-disabled/47785/12 "2024-12-02T19:55:48Z")

</div>

> [@charlifiiiii](#):
>
> Any recommandation ?

Perhaps you could try overriding `getDesktopScaleFactor` in your document window like so:

```auto
float getDesktopScaleFactor() const override
{
    return Desktop::getInstance().getGlobalScaleFactor() * desktopScale;
}

```

Here, `desktopScale` is a `float` data member that you set according to the editor’s current scale.
