2

I have created a GUI window is being called in the main method of another class. The window has a run button. The control should return to the main method only afterthe run button has been clicked. How do i get this functionality? Should i use threads?

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Alvin
  • 387
  • 4
  • 7
  • 18

1 Answers1

5

What you're describing is the classic behavior of a modal dialog such as a JOptionPane: program flow from the calling code pauses while the modal dialog is displayed and then returns at the calling spot when the modal dialog is no longer visible.

I suggest that you look into using a JOptionPane since this is usually the simplest way to get this behavior. Please understand that JOptionPanes can display complex GUI's since the second parameter of its showXXX(...) method is of Object type and can be a JPanel that is laden with other JPanels, components, and goodies.

For example, please look at the code from the answer to this question: How can I make a JFrame modal like a JOptionPane?


Edit
You state in comment:

can i make a JOptionPane from a JFrame? i made a JFrame with three file choosers and 3 text fields and a run button.can i make a JOptionPane from this JFrame direclty?

@Alvin: now you're learning why you should not be gearing your code towards creating JFrames -- you end up painting yourself in a corner. I suggest that you re-do that little bit of code and instead create a JPanel. Then you can put it into a JOptionPane, a JDialog, or JFrame or whatever the need dictates.

Community
  • 1
  • 1
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373