Solved

JDialog - Netscape 4.5 probelm

Posted on 2000-03-16
12
406 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
  • 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now