aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Program goes past where I think it should wait for Return from called program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Program goes past where I think it should wait for Return from called program" Watch "Program goes past where I think it should wait for Return from called program" New topic
Author

Program goes past where I think it should wait for Return from called program

Will Barbee
Ranch Hand

Joined: Oct 01, 2008
Posts: 41
This is a greenhorn question but it is about Swing.

I have a program which is processing and has an error message to display
so it calls a message-display program (so all messages look alike in the application).
The calling program is editing data entered into a JTextField and the processing is
occurring in the actionPerformed area.

I have Focus Listeners on the JTextFields and am processing a selectAll() statement when a
field is focussed on. Also, in the fields in question in this test, I have added a println "Focus Gained jtfieldname".

During execution, the calling program continues on past the message program call even though
the message program has not issued a return. It seems to me that the calling program should wait
for the called message program to complete before continuing on.

The calling program has the following code:


And the message program has the following code to display after the after the
JLabels are defined.



When I run the application and cause the error condition, the following message sequence prints:



At this point, I have not clicked on the Return button in the message program.
But the calling program has continued processing.

After I click on the Return button in the message JFrame, the println displays:


Why does the calling program not wait for the Return button to be pressed in the message program
before continuing on in its processing?

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Since Swing is an event-driven library, what you are describing is normal expected behavior. Don't you want to show a modal JDialog here, not a JFrame? The modal dialog will block program flow until it is dealt with.

For example, a runnable demo program:
Will Barbee
Ranch Hand

Joined: Oct 01, 2008
Posts: 41
Thanks, Pete.
I think I understand it.
I'll give it a test.
Will Barbee
Ranch Hand

Joined: Oct 01, 2008
Posts: 41
LESSON LEARNED:

Pete's program is quite instructive. It shows quickly how the Java processing works.

SO I modified the message program to use JDialog and all is well.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program goes past where I think it should wait for Return from called program
 
Similar Threads
Processing with two JComboBox's in one JPanel/JFrame
Hide a print dialog while printing a receipt
NX: URLy Bird 1.3.1 Suncertify.properties
is it possible to let jComboBox display the object's string field in th DefaultComboBoxModel Vector
calling another swing application to run when a button is click from my swing application