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

You have to overwrite even getBorderInsets(Component, Insets)

XMLWordPrintable

    • beta
    • x86
    • windows_nt


      Name: krT82822 Date: 01/20/99


      I noticed that when subclassing a Border-Class from
      AbstractBorder, I have to overwrite both methods:
      public Insets getBorderInsets(Component c)
      and
      public Insets getBorderInsets(Component c, Insets insets)

      because overwriting only getBorderInsets(Component c) will
      cause the getInsets()-method in JComponent to fail.

      Source-Code of JComponent.getInsets()-Mathod:
      public Insets getInsets(Insets insets) {
        if (border != null) {
          if (border instanceof AbstractBorder) {
            return ((AbstractBorder)border).getBorderInsets(this, insets);
          } else {
            // Can't reuse border insets because the Border interface
            // can't be enhanced.
            return border.getBorderInsets(this);
          }
        } else {
          // super.getInsets() always returns an Insets object with
          // all of its value zeroed. No need for a new object here.
          insets.left = insets.top = insets.right = insets.bottom = 0;
          return insets;
        }
      }

      You can notice that if the Border is inherited from AbstractBorder the
      getBorderInsets(Component, Insets)-Method will be called, so the Insets-Object
      gets recycled.

      The Problem is when overwriting only the getBorderInsets(Component)-Method, the called
      method will return always Insets(0,0,0,0)!

      In the swing package there are lots of Subclasses of AbstractBorder that does (MotifBorders)
      ONLY overwrite getBorderInsets(Component) and the getInsets() of the JComponent
      using this Borders return an incorrect value, so the getPreferredSize() is
      incorrect.
      (Review ID: 52407)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: