0

Whenever I open a JOptionPane.showInputDialog, the program I am writing comes to a "halt" and it waits for input. Or if I have a message dialog, the program halts and waits for the user to click Ok before proceeding with the rest of the code.

I created a JPanel that displays a picture and a button, however, when I run it and it shows set visible equal to "true", the JPanel appears, however, the program continues to run anyway down the other lines of code and does not stop.

Is it necessary to create listeners or boolean's in order to halt the program's current progress until an action is taken on the JPanel/JPane, or is there a simple way for the program to wait for a user's response to a JPanel/Jpane before proceeding?

king
  • 1,304
  • 3
  • 23
  • 43
  • 2
    You can add a panel to a JOptionPane, or you can create a modal JDialog. – camickr Apr 29 '15 at 03:03
  • 2
    [How to Make Dialogs](http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html) – MadProgrammer Apr 29 '15 at 03:04
  • I am familar with these dialog boxes, but they do not do what I need. For example, I need to display a JPG image and then a button and have the program stop. These dialog boxes seem very structured in that you have to do exactly what is in there, you can't edit them. That's why I made a JPanel and put a JPanel inside a JFrame, but I cannot make it stop there. Do you know what I am saying? – king Apr 29 '15 at 03:07
  • Why not simply put your JPanel into a modal JDialog? You'd do this just the same as you'd do with a JFrame. Understand that any *complex* JPanel GUI can go into a JOptionPane or JDialog, or JFrame just the same. And yes, we know what you're saying and then some, please trust us. – Hovercraft Full Of Eels Apr 29 '15 at 03:08
  • I don't understand when you say put it into a JDialog? A JDialog I thought had to be a certain type of box, like a message box or an input box? – king Apr 29 '15 at 03:09
  • A JDialog is **very similar to** a JFrame except that it can be modal -- just what you want. Please read the JDialog API entry. – Hovercraft Full Of Eels Apr 29 '15 at 03:09
  • is every JDialog modal? I attempted to add it, but it still is not filtering through all the way. – king Apr 29 '15 at 03:17
  • The example posted above is a JOptionPane.. I don't need a JOptionPane, I have my own JFrame and JPanel that is placed inside the JFrame. – king Apr 29 '15 at 03:18
  • 1
    No, you have to set it to be modal. For instance, if you call the constructor with your JFrame, it could look like: `new JDialog(myJFrame, "Title String", ModalityType.APPLICATION_MODAL);` – Hovercraft Full Of Eels Apr 29 '15 at 03:18
  • okay thanks, let me try that. this layout stuff is driving me nuts. – king Apr 29 '15 at 03:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76492/discussion-between-simon-and-hovercraft-full-of-eels). – king Apr 29 '15 at 03:19

0 Answers0