Solved

Disable/Enabled JDialog causes repaint

Posted on 2000-03-23
9
717 Views
Last Modified: 2008-03-10
Hi,

Sometimes in my program, I would like to disable a JDialog and change the mouse cursor to the Cursor.WAIT_CURSOR when the program is doing some processing. The problem is that when I disabled the JDialog throught setEnabled(false), the whole JDialog would flicker because it was repainted. What I don't understand is why the JDialog should repaint when I disabled (or enabled) it. Is there a better way of doing this?
0
Comment
Question by:yongsing
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:jerch
ID: 2651846
Hello yongsing...
For you to be able to avoid calling the paint method, a simple solution is to override the update method since the repaint method simply forwards it's call to the update method and the update method will clear the graphics or the jdialog (in your case) and schedule a call for the paint method.  Override the method update method with blank implementation.

cheers...
Jerson
0
 
LVL 9

Author Comment

by:yongsing
ID: 2652504
This is what I found in the JDialog class implementation:

    /**
     * Just calls <code>paint(g)</code>.  This method was overridden to
     * prevent an unneccessary call to clear the background.
     */
    public void update(Graphics g) {
        paint(g);
    }

Apparently the graphics isn't cleared.

Here's the setEnabled implementation:

        public void setEnabled(boolean b) {
            JDialog.this.setEnabled(b);
        }
What's JDialog.this.setEnabled(b) suppose to mean?
0
 
LVL 9

Author Comment

by:yongsing
ID: 2652558
This is what I found in the JDialog class implementation:

    /**
     * Just calls <code>paint(g)</code>.  This method was overridden to
     * prevent an unneccessary call to clear the background.
     */
    public void update(Graphics g) {
        paint(g);
    }

Apparently the graphics isn't cleared.

Here's the setEnabled implementation:

        public void setEnabled(boolean b) {
            JDialog.this.setEnabled(b);
        }
What's JDialog.this.setEnabled(b) suppose to mean?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 4

Expert Comment

by:jerch
ID: 2652966
What you see is actually the setEnabled method of the inner class AccessibleJDialog.  For a method of an inner class to call a method of the enclosing class (if the implementation of the enclosing class is hidden, which means that the inner class has a method with the same name and signature as the enclosing class, same case with the setEnabled method).  This is how you call it.  

<Enclosing Class>.this.<methodname>

e.g.

class Enclosing {
public void myMethod() {
//blah blah...
}

private class InnerClass {
public void myMethod() {
Enclosing.this.myMethod(); //this is how you call the method of the enclosing class inside an inner class.
}
}
}

For you to be able to see the code of the setEnabled of the JDialog.  Check the source code of the class Component since

java.awt.Component        |        +--java.awt.Container              |
              +--java.awt.Window                    |
                    +--java.awt.Dialog                          |
                          +--javax.swing.JDialog

and Container, Window and Dialog does not override the setEnabled method.  It now leaves you with the setEnabled of the Component class.

sincerely yours...
Jerson
0
 
LVL 9

Author Comment

by:yongsing
ID: 2659438
Hi,

I got what you mean, but what I don't understand now is this: the update method has already been overridden in JDialog, so how come the graphics is still being cleared?
0
 
LVL 4

Expert Comment

by:jerch
ID: 2659642
Yes, you're right the update method is overriden but the code actually calls the paint() method which cause it to repaint.

    public void update(Graphics g) {
        paint(g);
    }

Here's my suggestion.... Look at the skeleton class.

class MyJDialog extends JDialog {
    boolean refresh = true;
    public void setEnabled(boolean b) {
        refresh = false;
        super.setEnabled(b);
    }
   
    public void update(Graphics g) {
        if (update)
            paint(g);
        else
            update = true;                              
    }
}

I haven't tried this code but I think it will work. It will not work if the setEnable calls the update method more than once. Tell me the result.

cheers....
Jerson

0
 
LVL 9

Author Comment

by:yongsing
ID: 2671813
Hi,

Your code doesn't work. In your update(Graphics g) method, is the variable 'update' actually 'refresh'?

I looked at the setEnabled() method in the Component class, and it looks like it never asks for a repaint at all, and there isn't any override of this method in Container, Window, Dialog, and JDialog. So why is the JDialog repainted whenever setEnabled() is called?
0
 
LVL 4

Accepted Solution

by:
jerch earned 50 total points
ID: 2671982
Hi yongsing...
I tried disabling the JDialog. It's not calling the repaint method. Check this site http://www.javaworld.com/javaworld/javatips/jw-javatip87.html

You don't actually have to disable the dialog box.

best regards...
Jerson  
0
 
LVL 9

Author Comment

by:yongsing
ID: 2705943
Actually I do know about that web site, but I was hoping for something simpler.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
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 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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

809 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