Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

Non Modal JDialog does not show contents

Thread view: 
Rob Jones - 17 Mar 2004 13:58 GMT
Hi everyone.

I am trying to create a non modal JDialog
When I do this the Frame appears but there
is no contents. If I set the Dialog to be
modal it all appears fine.

Code...

public class ProcessingDialog extends JDialog
{

    public ProcessingDialog(JFrame parent)
    {
    //With this line uncommenetted the box appears fine
        //setModal(true);
        JLabel simple = new JLabel("Processing.");
        Container dialogContents = this.getContentPane();
        dialogContents.add(simple);
        pack();
    }

    public void showDialog()
    {
        show();
        //Same is true for
        //setVisible(true);
    }

}

BTW: Testing on Windows XP, JDK 1.4.2_01

Any ideas gratefully appreciated.

Thanks

Rob
Andrew Thompson - 17 Mar 2004 14:47 GMT
> public class ProcessingDialog extends JDialog
> {
>
>      public ProcessingDialog(JFrame parent)
>      {
        super( parent, true );
>     //With this line uncommenetted the box appears fine
>          //setModal(true);

This is an unusual way to get a modal dialog,
usually you pass the 'modal' part with the
constructor, as I did

>          JLabel simple = new JLabel("Processing.");
>          Container dialogContents = this.getContentPane();
>          dialogContents.add(simple);
>          pack();
    setVisible(true);

Now, this is the problem with code snippets,
it is only after I created a frame and handed
that as an object for the dialog, did I realise
that you must be _calling_ showDialog() from the
Frame right?

This is the source of your problems, as soon as
you set the Dialog modal, the Frame waits unitil
after it is closed before the frame does _anything_
else.  The showDialog() within your 'parent' is not
getting called..

>      }
>
>      public void showDialog()
>      {
>          show();

show() is deprecated, use setVisible(true)

>          //Same is true for
>          //setVisible(true);
>      }
>
> }

HTH

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Rob Jones - 17 Mar 2004 14:55 GMT
Thanks for reply Andrew,
You got my explanation wrong.
It is the *non* modal version that has a problem.

> Now, this is the problem with code snippets,
> it is only after I created a frame and handed
[quoted text clipped - 7 lines]
> else.  The showDialog() within your 'parent' is not
> getting called..

It is not as soon as you set a Dialog modal that it blocks
but as soon as you set a modal dialog visible that the call
blocks.
Regardless in my case it is non modal that is the problem.
But see my other mail. I non beleive the problem is in
the fact that I create these dialogs inside event loops
that is the problem. I also now see why modal is not a problem

Modal Version
------------
Event Loop started
Create modal dialog
Show dialog (draws and blocks until dispose())
Application Processing runs.
Dialog disposed

Non Modal Version
-----------------
Event Loop started
Create non modal dialog
show dialog (does not block and therefore delays drawing)
Application processing runs.
  (dialog drawing still not happened and therefore looks wrong)
Once application processing over dialog is presumerably drawn
correctly but as it is immediately disposed I never see it.
Andrew Thompson - 17 Mar 2004 15:56 GMT
> Thanks for reply Andrew,
> You got my explanation wrong.

Code speaks a thousand 'explanations'
<http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Steve W. Jackson - 18 Mar 2004 21:34 GMT
>:On Wed, 17 Mar 2004 12:58:01 +0000, Rob Jones wrote:
>:
[quoted text clipped - 44 lines]
>:
>:HTH

The show() method is *not* deprecated in Dialog.  It is deprecated in
Component.  Same with hide().

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Andrew Thompson - 18 Mar 2004 21:56 GMT
....
>>:>          show();

<Andrew Thompson>
>>:show() is deprecated, use setVisible(true)
</Andrew Thompson>
...
> The show() method is *not* deprecated in Dialog.  It is deprecated in
> Component.  Same with hide().

Ugghh.  It must have been late
when I wrote that..

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Rob Jones - 17 Mar 2004 14:49 GMT
Ok.
My problem lies with creating the non modal dialog within a
event loop. The processing which is being carried out (which
the non modal dialog box lets the user know is happening)
blocks the event from returning and therefore the new dialog
box is not getting painted.
Why this should work for Modal I dont know but I have the
start of a solution.

Rob

> Hi everyone.
>
[quoted text clipped - 34 lines]
>
> Rob
Steve W. Jackson - 18 Mar 2004 21:38 GMT
>:Ok.
>:My problem lies with creating the non modal dialog within a
[quoted text clipped - 6 lines]
>:
>:Rob

Swing automatically takes care of displaying modal dialogs from code
that's on the Event Dispatching Thread.  The original EDT does indeed
block, but a separate set of event pumps, etc., will start and handle
this situation perfectly.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Babu Kalakrishnan - 19 Mar 2004 14:18 GMT
> Ok.
> My problem lies with creating the non modal dialog within a
[quoted text clipped - 4 lines]
> Why this should work for Modal I dont know but I have the
> start of a solution.

Ah.. Are you trying to use a non-modal dialog to display progress while
you are doing some time-consuming task *in the event dispatch thread* ?

In which case this is a FAQ. There is only one EDT in swing, and unless
you finish your processing, it cannot do the task of painting your
non-modal dialog. And as for why the dialog displays if you make it
modal, it is simply because your "time-consuming" task doesn't even get
a chance to get executed until you've disposed off the dialog.

The solution ? Simple enough. Avoid doing any time consuming tasks from
the EDT. Instead do it in a separate thread.

BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.