Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enable button when jframe window is closed

 
John Devlon
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WindowListener
 
John Devlon
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2542
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic