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

component tests use component.visible instead of component.isVisible()

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
      Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      I am writing Swing components that override isVisible().

      My components render correctly because the java painting code correctly uses the isVisible() method rather than the Component.visible member variable.
      MouseEvents are not being delivered correctly when an invisible component covers another component because java.awt.Container.getMouseEventTargetImpl() tests for component visibility using comp.visible instead of comp.isVisible() at line 1733 in java1.4.2_01

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the given code
      try clicking both squares on the left and watch the console output
      this gives expected results.
      click on the center of the blue square on the right, which is obscured by an invisible red square


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "Right Blue clicked" will appear in the console output
      ACTUAL -
      "Right Red clicked" appears in the console output

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class VisibleTest extends JFrame {
          public static void main(String[] args) {
              new VisibleTest();
          }

          public VisibleTest() {
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              getContentPane().setLayout(null);
              getContentPane().add(new MyPanel(Color.RED, "Left Red", 25, 25, true));
              getContentPane().add(new MyPanel(Color.BLUE, "Left Blue", 35, 35, true));
              getContentPane().add(new MyPanel(Color.RED, "Right Red", 100, 25, false));
              getContentPane().add(new MyPanel(Color.BLUE, "Right Blue", 100, 35, true));
              setSize(200, 150);
              setVisible(true);
          }

          public class MyPanel extends JPanel {
              private boolean m_visible = false;
              private String m_description = null;
              public MyPanel(Color background, String description, int x, int y, boolean visible) {
                  setBackground(background);
                  setBounds(x, y, 50, 50);
                  m_visible = visible;
                  m_description = description;
                  addMouseListener(new MouseAdapter() {
                     public void mouseClicked(MouseEvent e) {
                         System.out.println(m_description + " clicked");
                     }
                  });
              }
              public boolean isVisible() { return m_visible; }
          }
      }
      ---------- END SOURCE ----------
      ###@###.### 2005-2-11 03:51:46 GMT

        Attachments

          Activity

            People

            • Assignee:
              dav Andrei Dmitriev (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: