Is there a easy way to replace AlertWindow::runModalLoop()?


Just found AlertWindow::runModalLoop() can't compile on Android OS.

Is there a easy way to replace it? Because I have some code using this method in many places. If I adopt DialogWindow to rewrite them one by one, it'll be a grind...

Thanks in advance.


You could create a component that covers your screen with a dark semi-transparent (or completely transparent or whatever) background and a pseudo dialog box on top with the appropriate buttons. 




Thanks, phil.

... then, how do I get the return value after make the pseudo dislog disappeared? Still have to write more codes, won't I?  


Thanks, Dave.

Yes,  if you do not need a return value, AlertWindow::showMessageBoxAsync() is a better and only way to replace the showMessageBox() from what I know about JUCE on Android. I've replaced all of this method by search and replace, which haven't taken my too much time :)

I'd apologize for my indistinct description. My situation is: I need one or two return value after clicked a button, then do some operations internally. For example:

AlertWindow window (...);

window.addButton (..., 0...); 
window.addButton (..., 1...); 
window.addButton (..., 2...); 

window.addTextEditor (...,1...);
window.addTextEditor (...,2...);

window.addComboBox (...);

window.add... //(more widgets);

const int result = window.runModalLoop();

if (0 == result)


else if (1 == result)


else if (2 == result)


I feel AlertWindow is a very handy class to do such things, so I used it nearly everywhere if it's possible. Now, I'm ready to pay the price... :)



Also, I've managed to use the PopupMenu::showMenuAsync() and a static callback function to replace PopupMenu::show(), so I think perhaps there is a method I haven't found yet for AlertWindow just like PopupMenu...


Well it's fairly easy to get whatever a dialogBox can return and more. If you just want to know which button was pressed use the buttonClicked method. You can enter inputs with a textEditor, etc. All you have to do is create a class once for all. And then use it for multiple usages.

When a button is clicked (eg OK or Cancel or whatever you decided to use) just use setVisible(false) to remove the pseudo dialog box.


Yes, phil, this's exactly what I thought before I posted this thread: rewrite all of them by custom Components, use some of the Component's methods, then get a DialogWindow::LaunchOptions to show it up. However, my situation isn't so simple, I have many AlertWindows, each of them have different widgets and behavior... One even has 5 buttons, 4 TextEditors, 2 ComboBoxes and a custom Component. :D

Like I said, I've used PopuMenu::showMenuAsync() and AlertWindow::showOkAndCancelBox (use static callback function) to modified the old codes easily, so I thought maybe there's a method perhaps could use a callback function or something else to replace AlertWindow::runModalLoops().

Now, I'm considering to write a class called AlertWindowForLoopfinesMiserable include the most methods of AlertWindow's, except the Component::runModalLoops()... :)

BTW, I think Jules should add some words to the comments of AlertWindow class, remind all JUCE programmers not to use runModalLoop() on any Android project....If I'm wrong again, please forgive it.



showMessageBoxAsync takes a ModalComponentManager::Callback* as a parameter so you can use it in a similar way to PopupMenu.


Thanks, guys. Finally, I got it run on Android. My nasty strategy was: wrote a new class, contains many methods same name as AlertWindow, made the buttonClicked() = 0; then derived child-classes for each of them...

Later on, I also encountered the FileChooser's modal issue,  what I did was using FileChooserDialogBox and static callbacks to kick it off.

There're still many problems on Android with my project though. However, see it running smoothly on this 'new' OS makes me very excited. I have to say, what a amazing library JUCE is!!! cool


Good work.

If you think your code is reusable for other JUCE Android developers, please consider making a JUCE module of your code :)


Yes, adamski, would love to do that if such a trivial thing could help others :) I always admire man who shared precious experiments and skills selflessly to the world, give helps to others, just like Jules and many, many people from this forum.

However, you see, the most difficult thing to me, not only have I known little about JUCE, but the horrible level of my English and programming as well. A lot of concepts and thoughts I can't explain them clearly, not to mention accomplish them elegantly within C++ and JUCE. I've been learning English, C++ and JUCE whenever I have time, all of these, very interesting to play with, and also are big challenges to me... I hope one day I could do something for others. :))


Different area, same question. I’m using AlertWindows in an Audio Plugin and as far as I don’t need more than messages and buttons, I can run them with the given show… functions. But now, I have one AlertWindow using a textEditor. We should not use runModalLoop (I understand, and it’s not working anyway), but what is the right way to run it so that I can still access the return values depending on which button was clicked? Or do I have to create my custom DialogWindow? Because the AlertWindow has the nice functionality to add components such as a TextEditor, I thought there must be a good way to run it too?
If enterModalState is the answer, I would be happy about a short example how to handle the callback…


Hi folks, I’m successfully using AlertWindows without modal loops (e.g. for Android compatibility).
I do that by constructing them, adding buttons / other components and then calling enterModalState. Callback Functions then handle my alert boxes.

Good examples on how to create them are listed in the documentation:

For example by using ModalCallbackFunction::forComponent, I turn alertWindow->getTextEditor() and the this pointer over to the callback, to have access to both, a text entered in an alertWindow, and the calling instance from inside the static callback function.