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

[macosx] Components in an active window sometimes display and act as if the window is inactive

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_112"
      Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin Alans-iMac 16.1.0 Darwin Kernel Version 16.1.0: Wed Oct 19 20:31:56 PDT 2016; root:xnu-3789.21.4~4/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Under certain circumstances, components using the Aqua LAF display and act as they would in an inactive window when the window is actually active.

      I believe the root of this problem is the use of the Frame.active client property to both notify a component of a change in the window active status and to inform the component of the current window active status.

      The problem arises when a component is removed from a component hierarchy in an inactive window and then installed in a new window. The Frame.active client properties are still present with value false, so the components assume they are in an inactive window. The client properties are not set to true until the new window is deactivated and reactivated.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached test program. Click the test button to display a new window. Click the dismiss button to dismiss the new window. Click the test button to display a second new window. Click on a file to select it. Click on the Cancel button.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The file chooser in the second new window should use the active list background color for the selected list item. The Cancel button should be enabled, which means it flashes when you click on it (although it does nothing in this case.)
      ACTUAL -
      The inactive list background is used. The Cancel button is disabled.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import java.awt.BorderLayout;
      import java.awt.FlowLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JButton;
      import javax.swing.JFileChooser;
      import javax.swing.JFrame;
      import javax.swing.JPanel;

      public class Test
      {
      public static void main(String[] args)
      {
      PrimaryFrame w = new PrimaryFrame();
      w.setBounds(100, 100, 400, 400);
      w.setVisible(true);
      }
      }

      class PrimaryFrame extends JFrame
      {
      private JFileChooser fc;

      public PrimaryFrame()
      {
      JPanel top = (JPanel) getContentPane();
      top.setLayout(new FlowLayout());

      fc = new JFileChooser();

      JButton testButton = new JButton("Test");
      top.add(testButton);

      testButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      TestFrame fr = new TestFrame(fc);
      fr.setBounds(500, 100, 400, 400);
      fr.setVisible(true);
      }
      });
      }
      }

      class TestFrame extends JFrame
      {
      public TestFrame(JFileChooser fc)
      {
      JPanel top = (JPanel) getContentPane();
      top.add(fc);

      JButton testButton = new JButton("Dismiss");
      top.add(testButton, BorderLayout.SOUTH);

      testButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      TestFrame.this.setVisible(false);
      }
      });
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Remove the component from the window hierarchy when the window is closed, before the window deactivate event is processed. That is what JFileChooser.showDialog() does.

            aniyogi Avik Niyogi (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: