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

JDesktopPane:getComponentCount() returns one extra than expected with GTKLookAndFeel

    XMLWordPrintable

    Details

      Description

      It’s observed that, getting the component count of the JDesktopPane returns one extra component than expected, when run with -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel.

      The spec of - https://download.java.net/java/early_access/jdk18/docs/api/java.desktop/java/awt/Container.html#getComponentCount()
      "Gets the number of components in this panel."

      Generally the Container(JDesktopPane) created fresh one does not expect any components by default.
      If the behavior of the JDesktopPane:getComponentCount() varies based on Look and feel then this should be stated explicitly in spec.

      Please find the code snipped to demonstrate the problem

      JDesktopPane jDesktopPane = new JDesktopPane();
      if (jDesktopPane.getComponentCount() == 0) {
          System.out.println("Expected : no child components present");
      } else {
          System.out.println("Unexpected : by default the jDesktopPane has components size " + jDesktopPane.getComponentCount() + " And the child component is " + jDesktopPane.getComponent(0));
      }


      Observation:
      =====

      /scratch/jdk-cache/17/34/jdk-17/bin/java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel JDesktopPaneCompTests
      Unexpected : by default the jDesktopPane has components size 1 And the child component is javax.swing.plaf.synth.SynthDesktopPaneUI$TaskBar

      /scratch/jdk-cache/17/34/jdk-17/bin/java JDesktopPaneCompTests
      Expected : no child components present

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              pbansal Pankaj Bansal
              Reporter:
              kganapureddy Krushnareddy Ganapureddy
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: