File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to restrict multiple Frames of the same class being opened by user? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to restrict multiple Frames of the same class being opened by user?" Watch "How to restrict multiple Frames of the same class being opened by user?" New topic
Author

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

A Hari Kiran
Greenhorn

Joined: Jul 28, 2009
Posts: 5
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
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Daniel Gen Li
Ranch Hand

Joined: Jan 02, 2010
Posts: 32
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.


Li
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Jul 28, 2009
Posts: 5
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

Joined: Feb 23, 2007
Posts: 1561
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.
 
Don't get me started about those stupid light bulbs.
 
subject: How to restrict multiple Frames of the same class being opened by user?
 
Similar Threads
Hide the Button When User Clicks On It
Closing a JFrame
multi-windowed application
Add New Record - Problem with GUI and JPanels
Listeners