• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Modal JWindow

 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Does anyone know if it is possible to force a JWindow to be modal? I have created a custom Dialog box using JWindow that stores user input from a field into a variable. I am calling this dialog from another application like this:
MyEnterDialog ed = new MyEnterDialog();
ed.show();
String theString = ed.getUserString();
The problem is that I now realize that JWindow is not modal, so when I call show(), the program continues to execute so that getUserString() is returning null because it has not been set by the user yet.
I know that I could extend JDialog instead of JWindow, but I am looking to do away with the title bar on the window if it is possible. Thanks very much for your help!!!

Barry
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just found the solution to my problem in case anyone is interested. All I have to do is override the show() method. In the show() method I can call setVisible() and then create an endless loop with while(true). The loop will break only when a boolean is true which will happen when the user presses a button. This will force the other window to wait until someone has pressed a button to execute the next line of code. I believe this will work. Does anyone else have a better idea?
Thanks,
Barry
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clever!!
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Cindy, but now I have run into another problem. First of all, I cannot override the show() method like I wanted to because for some reason my setVisible() method gets called many many times and Java does not like that. So, I created another method called hold() and put the while(true) loop inside that. The problem is that my dialog box never gets finished painting because when the hold() method is entered the CPU gets 'frozen.' I have also tried multi-threading, but cannot seem to get that to work either. Do you have any suggestions?
Thanks!!

Barry
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just use a JDialog with no title -
JDialog(Frame owner, boolean modal)
Creates a modal or non-modal dialog without a title and with the specified owner Frame.
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but I want no title bar at all. You can have no title, but the bar will still be there.

Thanks,
Barry
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i think there may be a way to do what you want by synchronizing on the JWindow once it has been created, then calling wait() on it. The running thread will now wait indefinitely until it is notified to resume running. To start it running again the JWindow must be synchronized on again and notify() then called on it.

hope this helps,
Dave
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,

I tried this thread synchronize and the JWindow i was trying show is not painted. It shows a unpainted JWindow which is white. Can you tell me what this could mean ??
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(replying to recent post, not those in 2001!)

seems easier to use an undecorated modal JDialog

something like this

 
Don't listen to Steve. Just read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic