?
Solved

Disable/Enabled JDialog causes repaint

Posted on 2000-03-23
9
Medium Priority
?
740 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 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