Solved

JDialog - Netscape 4.5 probelm

Posted on 2000-03-16
12
412 Views
Last Modified: 2008-03-17
We're developing an applet with swing components which uses a JProgressBar inside of a JDialog to display the progress of loading data from
our server to the screen.  All of this is running on the event thread.  The JDialog pops up, but the problem is that it doesn't paint any of its components (the JProgressBar and a JLabel) and thus remains blank.  This only occurs under Netscape, the JDialog paints fine under Visual Age and Marimba.  

My question is what causes this problem under netscape and is there any way I can force the JDialog to paint its components (JProgressBar and JLabel) so that they display?
0
Comment
Question by:CatDevlp00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:diakov
ID: 2625684
Describe in which thread you're downloading data and in which you update the dialog.

I suggest a separate thread that updates the progress bar during the data processing. You have to be carefull though, better use invokeLater() for the gialog updates as Swing components in general is not thread safe.

For example,

//run of the data thread
public void run()
{
  while (true)
  {
    //load some data
    ...
    //update gui
    SwingUtilities.invokeLater(new Runnable()
    {
      //this run will be called in the event thread      
      public void run()
      {
        dialog.label.setText("new text");
      }
    }
    );

    //is end? --> break;
  }
}

Cheers,
  Nik
0
 
LVL 10

Accepted Solution

by:
kollegov earned 100 total points
ID: 2626425
There is a bug in NN4 threads. When MODAL dialog popups
it blocks event dispatching thread. As the painting also
events base than this events hangs in queue...

Modal dialogs causes various other bugs in different browsers
platforms.

For example 2 modal dialogs in MIE5 both
continue threads after ONE closed.

On Solaris NN4  there also was some repainting bugs with Modal
dialogs.

The only safe solution is NOT use Modal dialogs..
Unless you write your own event dispatching

Other approach can be in releasing of event dispatching thread and
creating new thread in which you popup MODAL dialogs.





0
 
LVL 10

Expert Comment

by:kollegov
ID: 2626430
I forgot to tell, this is common problem for
any subclass of  dialogs which is MODAL
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 16

Expert Comment

by:heyhey_
ID: 2626808
I have used MODAL Dialogs (not JDialog) for quite a long time - without a single problem wiht IE / NN (Windows versions)

so I don't think that this is a modal problem :), but it would be nice to see some example code that blocks NN.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2627806
HeyHey, today I was fixing this problem again in some product :)

The problem is that if modal dialog have much nested components and requires significant time to repaint
you have chance (in NN4 winNT, Solaris) that thread will be blocked before dialog will be completely repainted.
This is stable reporoducable problem.

I fixed it quite easy way..

I made listener which shows dialog
Runnable and instead of direct showing window from ActionPerformed method
I started new thread (th) there.
Than run() method of the listener
had the following code
public void run(){
   Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
th.yield();
myDialog d=new MyDialog(...);
myDialog.show();
}

This completely solved problem..

Guess here the problem is the same..






0
 
LVL 10

Expert Comment

by:kollegov
ID: 2627807
HeyHey, today I was fixing this problem again in some product :)

The problem is that if modal dialog have much nested components and requires significant time to repaint
you have chance (in NN4 winNT, Solaris) that thread will be blocked before dialog will be completely repainted.
This is stable reporoducable problem.

I fixed it quite easy way..

I made listener which shows dialog
Runnable and instead of direct showing window from ActionPerformed method
I started new thread (th) there.
Than run() method of the listener
had the following code
public void run(){
   Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
th.yield();
myDialog d=new MyDialog(...);
d.show();
}

This completely solved problem..

Guess here the problem is the same..






0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2628371
I agree that slow paint() code may ruin a lot of things (not even the modal dialogs :), isn't it better to optimize that code :) - double buffering etc.

of course if there is a lot of Swing UI, you can't control it.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2628438
HeyHey...  The problem isn't in slow drawing itself, but in unguranteed event delivery time and order.
Slow code or processor load with other tasks only increase the probability..
Optimizing will decrease it, but probability always is.
0
 
LVL 8

Expert Comment

by:diakov
ID: 2628469
to Kolleqov:

Event order is always guaranteed. The order of execution of the code that puts this events in the event queue is not. You can order most of your GUI related code (provided you run several threads) using invokeLater, however this is quite tricky.

Cheers,
  Nik
0
 

Author Comment

by:CatDevlp00
ID: 2637539
to kollegov:

  Sorry, I don't quite understand your suggestion.  Are you saying that I should create the new JDialog with the JProgressBar under a new thread (separate) from the event thread

or

are you saying that I should update my JDialog from a separate thread?

to diakov:

  Are you suggesting a separate thread which creates my JDialog or do you mean to make my JDialog implement runnable and then try to update it through the required run method?

Sorry I wasn't quite clear what you two are getting at.  I would post the code but it's far too lengthy to be pasted here (it's a rather complex program).
0
 
LVL 8

Expert Comment

by:diakov
ID: 2638078
No, I suggest you instantiate your dialog as usual, but move the data handling in a separate thread. Then you do the dialog update by using invokeLater() together with an anonymous runnable instance.

Cheers,
  Nik
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2640327
I used something like this:

class AL implements
ActionListener,Runnable{
   Thread th=null;
   public void actionPerformed(...){
   
   Thread th=new Thread(this);
   if(th==null) th.start();
  }
 
  public void run(){
   Thread.currentThread().yield();
   //do whatever you did in actionPerformed here
   JDialog jd = ....;
   
   
  }
}

and this works :)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question