🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2065

Re: GUI problem

#2065
From: Stephen Langhardt
Date: Mon, 04 Jun 2001 09:50
89 lines
3927 bytes
Hi,

the problem is in the way you start the dialog. You prabably habe a button
or menu on your frame that will start the dialog. So the dialog is started
in the high priority event thread. But painting is done in a lower
priority thread and so your frame will be repainted only when
someOtherFunction and all the rest of the dialog constructor are finished.
If you don't want to handle with threads (why?) I know of only one other
way to do what you want but it uses threads implicitely:

public class MyDialog extends JDialog
{
    public MyDialog(Frame parent)
    {
        super(parent);
        ...
       SwingUtilities.invokeLater( new Runnable() {
         public void run() {
           someOtherFinction();
         }
       });
    }

This will append someOtherFunction to the end of the event queue. But you
have to invoke the repainting of the Frame outside of someOtherFunction
and can't use any results of it.

Hope this helps
Stephen


1.

Andrew \"Bass\" Shcheglov schrieb:

> Hi everyone!
>
> The problem is as follows.
> There're two classes:
>
> public class MyFrame extends JFrame
> {
>     public MyFrame()
>     {
>         ...
>     }
>     public void someFunction()
>     {
>         MyDialog dlg = new MyDialog(this);
>         dlg.setModal(true);
>         dlg.show();
>     }
> }
>
> public class MyDialog extends JDialog
> {
>     public MyDialog(Frame parent)
>     {
>         super(parent);
>         ...
>         someOtherFinction();
>     }
>
>     /**
>      * This function doesn't return for a long time, as it performs
> some complex math operations.
>      */
>     public void someOtherFunction()
>     {
>         ...
>     }
> }
>
> The first class represents my application's main frame. The second one
> is a dialog which may be called as a child of the main frame. But this
> dialog is being constructed for quite a long time (due to
> someOtherFunction() working -- see code above) -- about 30 seconds on
> my CPU. As a result, parent window is not being repainted. I need to
> explicitly repaint the main frame (parent window) from within
> someOtherFunction() (it contains a cycle). But standard methods such
> as revalidate() and repaint() do not help. Note: when the parent needs
> repainted, the child is not constructed yet.
>
> Who knows, how I can fix this problem without dealing with threads?
>
> Any suggestions will be appreciated.
> Thanks in advance.
>
>         Andrew.
Technical Details
Message-ID: <3B1B59F0.1945995C@arcormail.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news-fra1.dfn.de!newsfeed.arcor-ip.de!news.arcor-ip.de!212.144.193.84
References: <9feega$11u2$1@news.radio-msu.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,63855ae8d254f894
X-Google-Attributes: gid111d45,public
X-Google-Thread: 10fd6d,63855ae8d254f894
X-Google-Attributes: gid10fd6d,public
X-Google-Thread: 1089d0,63855ae8d254f894
X-Google-Attributes: gid1089d0,public
X-Google-Thread: 10a146,63855ae8d254f894
X-Google-Attributes: gid10a146,public
X-Google-Thread: f74b3,63855ae8d254f894
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-04 02:51:02 PST
Message-ID: <3B1B59F0.1945995C@arcormail.de>
Date: Mon, 04 Jun 2001 11:50:40 +0200
From: Stephen Langhardt <Stephen.Langhardt@arcormail.de>
X-Mailer: Mozilla 4.75 [de] (Windows NT 5.0; U)
X-Accept-Language: de
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api,borland.public.jbuilder.java.language,borland.public.jbuilder.java.swing,comp.lang.java.gui,comp.lang.java.programmer
Subject: Re: GUI problem
References: <9feega$11u2$1@news.radio-msu.net>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 212.144.193.84
X-Trace: 4 Jun 2001 11:49:50 +0100, 212.144.193.84
Lines: 90
X-Complaints-To: abuse@arcor-ip.de
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news-fra1.dfn.de!newsfeed.arcor-ip.de!news.arcor-ip.de!212.144.193.84