Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6838947

java.awt.Window.setBackground() doesn't throw IllegalComponentStateException for two-display conf

XMLWordPrintable

    • x86
    • windows_xp

      Problem is the same as described in 6838089, 6838942.
      Please see the following code:
      ------------------------------
      import javax.swing.*;
      import java.awt.*;
      import static java.lang.System.out;

      public class SettingBackground {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                      GraphicsDevice[] devices = ge.getScreenDevices();
                      Frame window = new Frame("My frame");
                      window.setBackground(Color.RED);
                      GraphicsDevice device = devices[0];
                      out.println("using device " + device);
                      device.setFullScreenWindow(window);
                      out.println("device.getFullScreenWindow() = " + device.getFullScreenWindow());
                      try {
                          window.setBackground(new Color(30,30,30,100));
                          System.out.println("No IllegalComponentStateException");
                          GraphicsConfiguration gc = window.getGraphicsConfiguration();
                          out.println("device = " + gc.getDevice());
                          out.println("device.getFullScreenWindow() = " + gc.getDevice().getFullScreenWindow());
                          // onbe can see elliptical shape of the window
                          Thread.sleep(1000);
                      } catch (IllegalComponentStateException e) {
                          System.out.println("OK - IllegalComponentStateException thrown");
                      } catch (InterruptedException e) {
                      } finally {
                          window.dispose();
                      }
                  }
              });
          }
      }

      ------------------------------
      On two-monitor configuration it prints out:

      using device Win32GraphicsDevice[screen=0]
      device.getFullScreenWindow() = java.awt.Frame[frame0,1280,0,1280x1024,layout=java.awt.BorderLayout,title=My frame,resizable,normal]
      No IllegalComponentStateException
      device = Win32GraphicsDevice[screen=1]
      device.getFullScreenWindow() = null
      ------------------------------

            dcherepanov Dmitry Cherepanov
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: