Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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
  • 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
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
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
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic