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

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

XMLWordPrintable

    • b116
    • x86
    • windows_xp
    • Verified

      method java.awt.Window.setOpacity(float opacity)

      declares:
       * @throws IllegalComponentStateException if the window is in full screen
       * mode, and the opacity is less than 1.0f

      This is not true if using two-monitor configuration on WindowsXP(SP3).
      Please see the following code sample with extended console output:
      -------------------------------------------
      import javax.swing.*;
      import java.util.Arrays;
      import java.awt.*;
      import static java.lang.System.out;

      public class Temp {

          public static void main(String[] args) throws Exception {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                      GraphicsDevice[] devices = ge.getScreenDevices();
                      out.println("Arrays.toString(devices) = " + Arrays.toString(devices));

                      Frame window = new 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.setOpacity(0.1f);
                          out.println("no IllegalComponentStateException !!!");

                          GraphicsConfiguration gc = window.getGraphicsConfiguration();
                          GraphicsDevice gd = gc.getDevice();
                          out.println("gd = " + gd);
                          out.println("window = " + window);
                          out.println("gc.getDevice().getFullScreenWindow() = " + gc.getDevice().getFullScreenWindow());
                          out.println("(window == gc.getDevice().getFullScreenWindow()) == " + (window == gc.getDevice().getFullScreenWindow()));
                      } catch (IllegalComponentStateException e) {
                          out.println("IllegalComponentStateException - ok");
                      }
                      window.dispose();
                  }
              });
          }
      }
      -------------------------------------------
      The output is:

      Arrays.toString(devices) = [Win32GraphicsDevice[screen=0], Win32GraphicsDevice[screen=1]]
      using device Win32GraphicsDevice[screen=0]
      device.getFullScreenWindow() = java.awt.Frame[frame0,1280,0,1280x1024,layout=java.awt.BorderLayout,title=,resizable,normal]
      no IllegalComponentStateException !!!
      gd = Win32GraphicsDevice[screen=1]
      window = java.awt.Frame[frame0,1280,0,1280x1024,layout=java.awt.BorderLayout,title=,resizable,normal]
      gc.getDevice().getFullScreenWindow() = null
      (window == gc.getDevice().getFullScreenWindow()) == false

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: