• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to restrict multiple Frames of the same class being opened by user?

 
A Hari Kiran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

I am working on a swing application where in when a user clicks on a button, a new JFrame will be created.
But we have to restrict creation of another JFrame when user clicks on the button again.

Or can you atleast tell me how to constraint the user to the new frame..
Ex : when a JOptionpane is created, until and unless user closes it, he will not be able to click any where else..

Thanks,
Hari.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ashk gnec wrote:



Like I requested you before, you really really need to check your private messages and act on it. This is not optional.
 
Daniel Gen Li
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take note of how you make the JOptionPane:

That would be the GUI for your case. Note the "null" parameter that I passed. That parameter is used to tell Java which this OptionPane belongs to. In other words, which windows that can only be used again if the OptionPane gets a result. Usually, I just out "this" (the java keyword) in the place for the null, because I extend JPanel for some of my GUI related programs.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A Hari Kiran wrote:Hi Friends,

I am working on a swing application where in when a user clicks on a button, a new JFrame will be created.
But we have to restrict creation of another JFrame when user clicks on the button again.

Or can you atleast tell me how to constraint the user to the new frame..
Ex : when a JOptionpane is created, until and unless user closes it, he will not be able to click any where else..

Thanks,
Hari.



Don't open another JFrame but instead use a modal JDialog. This is specifically what they are for.
 
A Hari Kiran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks All,

Its was simple but couldn't find the method then.
For those who are still searching for an answer,

create a JDialog instead of a JFrame.
and use this method "setModal(true);"
It takes care of the issue.

Regards,
Hari.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A Hari Kiran wrote:
Its was simple but couldn't find the method then.
For those who are still searching for an answer,

create a JDialog instead of a JFrame.
and use this method "setModal(true);"
It takes care of the issue.

Regards,
Hari.



That's great advice. I wish that I had thought of it.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic