简体   繁体   中英

How to make a JFrame dialog like a JOptionPane.showMessageDialog() waiting for press a button in Java?

I'm not trying to make just a dialog. I have a JFrame object, and I need it shows first when running other class, but I need that when JFrame object executes, It makes to wait/pause/stop to the main class, something like JOptionPane dialogs. I don't want the other class executes behind the JFrame object, I want it waits to make something (like press a button) in JFrame Object.

Is there a property for that?

How can I do what I want?

Thanks!

You can use a Modal (J)Dialog. If you check the Javadocs, you'll see the method setModal.

But the far easier way to do this (IMO) is to create a custom JPanel and show it with JOptionPane using the same showXXXDialog methods you've been using.

I found an easier way to make what I wanted. To explain, I only created a JPanel with the same design of the JFrame object that I had. JOptionPane can show custom JPanel objects. making a JPanel into a JOptionPane.OK_OPTION

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM