Solved

JDialog - Netscape 4.5 probelm

Posted on 2000-03-16
12
411 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

734 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