• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to prevent multiple instance of jframe  RSS feed

 
Joshua Ebarvia
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.

I have an application with two buttons, buttonDisplay and buttonExit.
If buttonDisplay is clicked jFrameDisplay is instantiated/created and displayed. However if I click buttonDisplay in my first frame, another instance of jFrameDisplay is created. How can I prevent other instances of jFrameDisplay, if there is already one created.

I have used private final JFrame jFrameDisplay = new JFrame() as a field variable in my first frame to make it model. However, in my jFrameDisplay, I have added that if it is closed, it will call this.dispose(). Everything is fine except that when I click buttonDisplay of the first frame, no more instance of jFrameDisplay is created. How can I create new instance after disposing it.

Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are a few options.

1. Disable the buttonDisplay button until the second JFrame is closed.
2. Set a boolean property like frameOpen and check that for true if the button is clicked again. Set it to false when the second JFrame is closed.
3. Don't use a JFrame for the second frame. Maybe a model JDialog would be better. That way the first frame isn't accessible until the dialog is closed.

Without knowing more about your application that's the best I can come up with.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!