Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:42:07+00:00 2026-05-22T18:42:07+00:00

I am experiencing a problem with Swing that only occurs when the computer monitor

  • 0

I am experiencing a problem with Swing that only occurs when the computer monitor is powered off, but my Swing application continues to run in the background. It seems that whenever the monitor is off, Swing/AWT cancels all painting operations, leading to a number of display issues in the GUI that are visible as soon as the monitor turns back on.

For example, when I turn off the monitor using a custom JNI function and subsequently open a simple message dialog, the message dialog is blank when the monitor turns back on:

Blank message dialog

But it paints correctly after the next repaint:

Correctly painted message dialog

Is this the expected behavior of Swing? Is there a way to instruct Swing to continue drawing to the screen even if the monitor is powered off?

EDIT: Here is an SSCCE:

package test;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class App {
    public static void main(String[] args) throws Throwable {
        System.out.println("***** Please turn off the monitor in the next 70 seconds *****");
        Thread.sleep(1000L * 70);

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(null, "Test");
            }
        });
    }
}

I am using 64-bit Windows 7 Home Premium SP1 and 64-bit Java 1.6.0_24.

EDIT 2: Here is another program with which I experience the effect of "canceled painting operations":

package test;

import static com.mycompany.Util.turnOffMonitors;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

public class DialogTest extends JDialog {
    private final JLabel label;

    public DialogTest() {
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        label = new JLabel("Test", JLabel.CENTER);
        label.setOpaque(true);

        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        contentPane.add(BorderLayout.CENTER, label);

        this.setPreferredSize(new Dimension(200, 110));
        pack();
        setLocationRelativeTo(null);
        setVisible(true);

        Thread t = new Thread() {
            @Override
            public void run() {
                turnOffMonitors();
                try {
                    Thread.sleep(3000L);
                } catch (InterruptedException ex) { }

                SwingUtilities.invokeLater(new Runnable() {
                   @Override
                   public void run() {
                       label.setBackground(Color.YELLOW);
                   }
                });
            }
        };
        t.start();
    }

    public static void main(String[] args) throws Throwable {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new DialogTest();
            }
        });
    }
}

Before the monitor shuts off, I see:

Screenshot of the dialog of DialogTest before the monitor shuts off

With the monitor off, the label background color is changed to yellow in the background. I then move the mouse to turn the monitor back on. The dialog is visually unchanged. It is only after I force a repaint (by ALT-TABbing, for example) do I see the yellow:

Screenshot of the dialog of DialogTest where the main label has a yellow background

EDIT 3: Reported to Oracle as Bug ID 7049597.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:42:08+00:00Added an answer on May 22, 2026 at 6:42 pm

    I then started the program and stopped
    moving the mouse/typing. After one
    minute, the screen turned off. I
    waited another 20 seconds to move the
    mouse. The monitor turned back on and
    I saw a blank message dialog.

    Using your example, I don’t see this on my (non-Windows) platform. You might try the example below, which should alternate between WINDOW_ACTIVATED on wake and WINDOW_DEACTIVATED on sleep. If so, you could extend JDialog and repaint() in windowActivated().

    import java.awt.EventQueue;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    
    /** @see http://stackoverflow.com/questions/6163606 */
    public class DialogEventTest extends JDialog {
    
        public DialogEventTest() {
            this.setLayout(new GridLayout(0, 1));
            this.add(new JLabel("Dialog event test.", JLabel.CENTER));
            this.add(new JButton(new AbstractAction("Close") {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    DialogEventTest.this.setVisible(false);
                    DialogEventTest.this.dispatchEvent(new WindowEvent(
                        DialogEventTest.this, WindowEvent.WINDOW_CLOSING));
                }
            }));
        }
    
        private static class WindowHandler extends WindowAdapter {
    
            @Override
            public void windowActivated(WindowEvent e) {
                System.out.println(e);
            }
    
            @Override
            public void windowDeactivated(WindowEvent e) {
                System.out.println(e);
            }
        }
    
        private void display() {
            this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            this.addWindowListener(new WindowHandler());
            this.pack();
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new DialogEventTest().display();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experiencing an intermittent problem with a class that extends javax.swing.text.DefaultStyledDocument . This document
I'm no hero with .htaccess, but I'm experiencing a problem that I think might
I am experiencing problem in my application with OutOfMemoryException. My application can search for
I am experiencing a problem with my circularlinkedlist. it is a list, that is
I'm experiencing a problem with a Classic ASP application I'm maintaining (the architect is
The build machine at work has many projects, but we are only experiencing a
im experiencing this problem when deploying my django application to heroku , it says
I'm trying to use ProGuard to obfuscate a Java application. I'm experiencing a problem
I am experiencing a problem where Rational Application Developer 8 consistently hangs indefinitely on
I'm starting to learn mod_rewrite and experiencing a problem that I can't solve myself.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.