• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modal JWindow  RSS feed

 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clever!!
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Dave Turner
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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
 
chakri s
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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 ??
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(replying to recent post, not those in 2001!)

seems easier to use an undecorated modal JDialog

something like this

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!