Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dailog to inform parent that it is closing

Status
Not open for further replies.

JamesGordon

Programmer
Jan 14, 2002
70
GB
I have a JFrame with a toggle button. The toggle button shows/hides a JDialog, all well and good.
What I want to be able to do is inform the JFrame that the user has closed the JDialog via the 'X' of the JDialog and then toggle the button to the off state.

Does anybody have an idea on how to achieve this?

Many thanks.

James.
 
In your JDialog, you have to create an inner class to handle the window events. windowClosing is the event you need, so you add the code to notify the JFrame there.

Your code would then look something like this:

Code:
public class Foo extends JDialog {
	public JDialog(){
		...
		addWindowListener(new WindowHandler);
		...
	}
	...
	private class WindowHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e){
			// add code to notify JFrame
		}
	}
}

regards,
Blaxo
 
Yep! I got that by shear fluke. It's the code to notify the JFrame I'm missing?

I cannot pass the JFrame in as the parent as it expects a Frame not a JFrame?
 
Sorted, I got the parameters wrong, assumed the constructor was (Frame, boolean) not (Frame, String, boolean), sorry!

I then created a method in the JFrame and in the JDialog cast the WindowEvent.getParent() to my JFrame class and called the method to alter the togglebutton.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top