• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I guess I'm back to using JFrame again Thank you for answering my question.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic