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

Doc for javax.swing.plaf.basic.xxxUI.installUI() need correction




      Name: ooR10001 Date: 03/07/2001

      Specification for installUI() method for all UI classes in
      javax.swing.plaf.basic package has been coped from
      javax.swing.plaf.basic.ComponentUI class, but it contradicts with current
      ideology of creating and managing UI. Also, there is no doc for
      installDefaults() and installListeners() methods and it is unclear how to use
      them in derived classes. There is an example which shows this contradiction:

      Lets consider common UI class SomeBasicUI. It's methods installUI() and
      installDefaults() do some abstract initialization work.
      import javax.swing.plaf.basic.BasicButtonUI;
      import javax.swing.JComponent;

      public class SomeBasicUI extends BasicButtonUI {

        public void installUI(JComponent c) {
            System.out.println("Install default value 1");

        public void installDefaults() {
            System.out.println("Install default value 1");


      Suppose we attempt to create next UI class MyUI based in SomeBasicUI class, but
      we don't know at this moment about SomeBasicUI implementation. In MyUI class we
      want to have another default initialization and overriding installDefaults()
      method for our needs:

      import javax.swing.JButton;

      class MyUI extends SomeBasicUI {

        public void installDefaults() {
            System.out.println("Install default value 2");


      public class test {

          public static void main(String[] args) {
              JButton button = new JButton();
              MyUI ui = new MyUI();


      We expect that installUI() in this case correctly installs default values for
      UI according to installDefaults() method, but it is not happened:

      Install default value 1

      For expected result we need to oiverride installUI() method too and duplicate
      initialization code in it.

      More flexible case is to invoke installDefaults() in installUI() method - in
      this case we wouldn't need code duplication in installUI method and would not
      depend from future installDefaults() overrides.

      The same situation applies to installListeners() method. Overriding this
      method doesn't necessary result in a fact these properties are correctly

      Current javadoc does not specify installXXX() method and does not explicity say
      when and from where installDefaults() and installListeners() methods are called.

      If it have been explicity defined that installDefaults() and installListeners()
      method should be called from installUI() then we would have more correct and
      stable scheme for UI initialization. Note, though the reference implementation
      has been designed in a prooper way, any other implementations are free to be
      incorrectly designed if they are based on the current spec.

      Current javadoc needs to be fixed according to UI ideology. The spec for
      installUI() method should specify that it's behavior is delegated to
      installXXX() methods. Also, each BasicXXXUI class should have it's own
      specification for installUI() method.





            Unassigned Unassigned
            oovsunw Oov Oov (Inactive)
            0 Vote for this issue
            0 Start watching this issue