• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to prevent multiple instance of jframe

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic