Solved

JDialog - Netscape 4.5 probelm

Posted on 2000-03-16
12
409 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 71
MySqlDump not dumping triggers 1 43
String array comparison 4 38
How  can  i  resolve  HTTP Status 404 -? 8 42
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

839 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