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

JWindow with the background color of the α 0 does not appear

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 7u55, 8, 9
    • client-libs

      FULL PRODUCT VERSION :
      1.8.0_05

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 x64 ver 6.1

      A DESCRIPTION OF THE PROBLEM :
      After WindowEvent.WINDOW_ICONIFIED occurs in the owner of JWindow that set the background color to transparent, JWindow is not drawn when the WindowEvent.WINDOW_DEICONIFIED happened to owner.

      ADDITIONAL REGRESSION INFORMATION:
      1.7 probably all


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      import java.awt.*;
      import java.awt.event.*;

      import javax.swing.*;
      import javax.swing.border.LineBorder;


      public class DeIconified_Bug extends JFrame {

          //
          // Static implementation.
          //
          static void ToCenterByWindow(Window frame, Window owner)
          {
              Dimension d;
              Point p = null;
              if(owner == null) {
                  d = Toolkit.getDefaultToolkit().getScreenSize();
              }
              else {
                  d = owner.getSize();
                  p = owner.getLocation();
              }

              Dimension frameSize = frame.getSize();
              if (frameSize.height > d.height)
                  frameSize.height = d.height;
              if (frameSize.width > d.width)
                  frameSize.width = d.width;

              if(p != null) {
                  p.x += (d.width - frameSize.width) / 2;
                  p.y += (d.height - frameSize.height) / 2;
              }
              else {
                  p = new Point((d.width - frameSize.width) / 2, (d.height - frameSize.height) / 2);
              }
              frame.setLocation(p);
          }

          static void createAndShowGUI() {
              DeIconified_Bug bug = new DeIconified_Bug();
              ToCenterByWindow(bug, null);
              bug.setVisible(true);
          }
          /**<pre>
           * </pre>
           *
           * @param args
           */
          public static void main(String[] args) {
              EventQueue.invokeLater(
                  new Runnable() {
                      @Override public void run() {
                          createAndShowGUI();
                      }
                  }
              );
          }
          
          //
          // instance implementation.
          //
          DeIconified_Bug() {
              initialize();
              super.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          }
          private void initialize()
          {
              JPanel panel = new JPanel();
              getContentPane().add(panel, BorderLayout.NORTH);
              JButton openJWindow = new JButton("Open window");
              panel.add(openJWindow);
              openJWindow.addActionListener(new OpenJWindowAction());
              openJWindow.setName("openJWindow");
              
              JPanel panel_1 = new JPanel();
              panel_1.setPreferredSize(new Dimension(300, 200));
              panel_1.setBorder(new LineBorder(new Color(0, 0, 0), 2));
              getContentPane().add(panel_1, BorderLayout.CENTER);
              super.pack();
          }
          class OpenJWindowAction implements ActionListener {
              @Override
              public void actionPerformed(ActionEvent e) {
                  JLabel lbl = new JLabel("Dummy window", SwingConstants.CENTER);
                  lbl.setFont( Font.decode("Monospaced bold 16") );
                  lbl.setPreferredSize( new Dimension(200, 100) );
                  lbl.setBackground( Color.orange );
                  lbl.setOpaque(true);
                  lbl.setBorder(new LineBorder(new Color(255, 0, 0), 1));

                  JWindow jw = new JWindow(DeIconified_Bug.this);
                  jw.getContentPane().add(lbl);
                  jw.setBackground( new Color(0, true) );
                  jw.pack();
                  ToCenterByWindow(jw, DeIconified_Bug.this);
                  jw.setVisible(true);
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
          // will override the processWindowEvent of owner window.
          @Override
          protected void processWindowEvent(WindowEvent e)
          {
              super.processWindowEvent(e);
              switch (e.getID()) {
                  case WindowEvent.WINDOW_DEICONIFIED: {
                      for (Window window: Window.getWindows()) {
                          if (window != this && window instanceof JWindow) {
                              Color c = window.getBackground();
                              if (c.getAlpha() < 0xFF) {
                                  window.setBackground( new Color(c.getRGB()) ); /* no alpha */
                                  window.setBackground(c);
                              }
                          }
                      }
                      break;
                  }
              }
          }

            pkbalakr Prem Balakrishnan (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: