Java pop-up box hiding behind everything

NAMEWITHELD12 used Ask the Experts™
I am using this command in a small Java program to show a pop-up box if a line of text in a file has a bunch of ****s in front of it.  Rules are:

- Don't show the stars
- Pop-up the box in front of all windows

The stars aren't shown, the box does show up, but it's *behind* everything instead of in front of it, making it look like the entire program is frozen/stuck.  How can I force it to show up in front instead?

if (animal.contains("*")) {
                  animal = animal.replace("*", "");
                  JOptionPane.showMessageDialog(popUp, animal); // this is the single line of code for the pop-up box
               else {
                  animal = inFS.nextLine();
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Yes, you''ll need to put your JOP into some other container that supports the setAlwaysOnTop() method.


I'm super junior at Java -- could you link me to what the container should look like or provide an example?  Hopefully something simple..
You could use a JDialog for example. Have a go after looking at the API for that first.


I was able to fix it by adding this code:

JFrame frame = new JFrame();

 JOptionPane.showMessageDialog(frame, animal);

Thanks for the advice!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial