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

RFE: Look and Feel classes are poorly designed and hostile to subclassing

    XMLWordPrintable

Details

    Description



      Name: jk109818 Date: 02/21/2003


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


      A DESCRIPTION OF THE PROBLEM :
      The Pluggable Look and Feel classes are designed in such a
      way as to make sensible overriding extremely difficult and
      frustrating.

      As a simple example, the Windows Look and Feel renders
      disabled menuitems incorrectly (which I have submitted in a
      separate bug report). I would like to fix that bug now,
      rather than wait the expected two or more years for a fix to
      be available from Sun.

      So, a quick investigation revealed that BasicMenuItemUI is
      painting the accelerator text in a massive 6KB method.
      There is no paintAccelerator() method that I could override
      in order to fix the bug with accelerator display, which
      means that I would have to copy the entire 6KB
      paintMenuItem() method to alter this behavior.
      Unfortunately, paintMenuItem() depends on the 5KB
      layoutMenuItem(), which is private, and I would therefore
      have to copy the entire code of that method as well.

      So, to be able to modify the accelator paint behavior in any
      way, I have to copy 11KB of code into a subclass of
      WindowsMenuItemUI. I can then make the required *ONE LINE*
      change to the painting behavior.

      I hope I'm not the only one that finds that to be absurd.

      Unfortunately, this is far from an isolated example. Unlike
      the rest of Swing, the PLAF classes do not seem to have been
      designed with anything approaching sane design principles,
      requiring ridiculous amounts of effort and code duplication
      to solve simple problems. Many of these giant, monolithic
      methods need to be broken up so that they can be overridden
      in reasonable ways, and a number of methods and fields that
      are marked private should instead be protected.

      I have no doubt that this will instantly be hit with the
      dreaded "Will Not Fix" club, but I figure it's worth a shot.

      REPRODUCIBILITY :
      This bug can be reproduced always.
      (Review ID: 181547)
      ======================================================================

      Attachments

        Activity

          People

            Unassigned Unassigned
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: