aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Enable button when jframe window is closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Enable button when jframe window is closed" Watch "Enable button when jframe window is closed" New topic
Author

Enable button when jframe window is closed

John Devlon
Greenhorn

Joined: Jun 27, 2013
Posts: 12
Hi,

I have smalll application, containing 2 jFrame forms.

When clicking on a menu item in form 1, on the current form a button is disabled, and a second form is displayed.
When the second form is closed, the button on the first form has to be re-enabled.

Does anyone know how to do this? How to get the button object on the first form and change it's propeties?

Thanks
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

WindowListener


luck, db
There are no new questions, but there may be new answers.
John Devlon
Greenhorn

Joined: Jun 27, 2013
Posts: 12
Hi Darryl,

Thanks for your feedback.

I've tried on Form 1 to...

if (wdForm2 == null){
wdForm2 = new Form2();

wdForm2.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent ev) {
btnStart.setEnabled(true); // Located on form 1
}
});

}
wdForm2.setVisible(true);



.. but it doesn't seem to work...

Has anyone any suggestion?

Thanks
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

ItDoesntWorkIsUseless (<- click), please be more specific. The general principle proposed above should do the trick. Though, I would suggest you never have more than one JFrame per application; use JDialog instead.


The quieter you are, the more you are able to hear.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

John Devlon wrote:
I have smalll application, containing 2 jFrame forms.

Bad usability. I would recommend using something like a CardLayout or explicitly replacing visual component containers
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
I have smalll application, containing 2 jFrame forms.


Also, agree this is a bad design. An application should only contain a single JFrame.

If you need child windows, then you should create a modal JDialog. There is no need to disable the original button because you won't be able to access the the frame again until you close the dialog.

Or, has already been mentioned you can use a CardLayout.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enable button when jframe window is closed