This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
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.
 
Bartender
Posts: 11445
18
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.
 
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.
 
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!