File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiating a JDialog in constructor - won't execute other lines..

 
Besjamain Greenaway
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took on the advice to use a JFrame for my first screen, and a JDialog for al the other screens. I use a strategy pattern to separate the looks from the behaviour. In the constructor of my behaviour class I instatiate the class for the looks:
Where TafelView is my new screen (JDialog)

Unfortunately, these lines won't run, because it stops on the line that makes the JDialog:

How can I do it so that these lines will run?
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe Dialogs are intended to prompt user input:
A Dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window.

The Swing Tutorial: How to make Dialogs.
so they pause the execution of the thread they are spawned from.
If you don't want to wait for user input, I believe you'll want to use another Frame (or InternalFrame, if you want to block input to the main frame).
 
Besjamain Greenaway
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I have a main frame, with a couple of buttons on it. When one of those buttons is clicked, a second window comes up. That second window has a form on it; a couple of labels + textfields, and two buttons "save" and "cancel". I first did it with a JFrame, but was advised to use a JDialog instead. But then this problem arises, and I don't know what to do know.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besjamain Greenaway wrote: I first did it with a JFrame, but was advised to use a JDialog instead.


I looked through your previous posts for that advice and couldn't find it. Why was a JDialog advised over a JFrame?
 
Besjamain Greenaway
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, here is part of one it:
Wouldn't you be better off having a JDialog sitting above the main JFrame rather than a second JFrame? Then there is absolutely no danger of closing the app when the dialog closes, you can better control modality type, and you can guarantee that the subwindow always sits above the main one.


I read about it somewhere else as well, but I can't find it that quick, although I have a hunch that I read it on Sun's website somewhere. But I'm guessing that you say that it's okay?
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google says it is here. I just wanted to see the context of your question and the answer.
I would not say using JDialog is "OK". It doesn't do what you want it to do. I think you have two options (there may be more):
1. use a JDialog with the understanding that processing in that thread halts
2. use a second JFrame or a JInternalFrame and continue processing in the background.
 
Besjamain Greenaway
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I guess I'm back to using JFrame again Thank you for answering my question.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also make the dialog non-modal, that will also not block the method.
 
Besjamain Greenaway
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great, less adjusting! I'll go and find out what would be more preferrable then, because I don't really see why a JFrame or JDialog or visa versa apart from the modality.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic