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

Incosistency in several SynthUI classes between inherited specs of update() and paint() methods

XMLWordPrintable

    • b84
    • generic
    • generic

      There's an inconsistency between the specification of methods that is inherited and the behavior of the methods. Specification should be updated.

      For example in class javax.swing.plaf.synth.SynthButtonUI method paint(Graphics g, JComponent c) is overridden and the spec is inherited:

       * This method is invoked from the ComponentUI.update method when the specified component is being painted.

      method update(Graphics g, JComponent c) is overridden as well and the spec is also inherited without any changes. In fact the overridden update method doesn't call paint(Graphics, JComponent), but calls paint(SynthContext, Graphics)

      This should be clearly specified as for now behavior contradicts the spec.

      Please see the following code sample:

      -------------------------------------
      import javax.swing.*;
      import javax.swing.plaf.synth.*;
      import java.awt.*;

      public class PaintTest {

          public static void main(String[] args) throws Exception {
              SwingUtilities.invokeAndWait(new Runnable() {
                  @Override
                  public void run() {
                      runTest();
                  }
              });
          }

          private static void runTest() {
              try {
                  UIManager.setLookAndFeel(new SynthLookAndFeel());
              } catch (UnsupportedLookAndFeelException e) {
                  throw new RuntimeException(e);
              }
              JButton button = new JButton("A Button");
              button.setUI(new SynthButtonUI() {
                  @Override
                  public void update(Graphics g, JComponent c) {
                      System.out.println("called update(Graphics g, JComponent c)");
                      super.update(g, c);
                  }
                  @Override
                  public void paint(Graphics g, JComponent c) {
                      System.out.println("called paint(Graphics g, JComponent c)");
                      super.paint(g, c);
                  }
                  @Override
                  protected void paint(SynthContext context, Graphics g) {
                      System.out.println("called paint(SynthContext context, Graphics g)");
                      super.paint(context, g);
                  }
              });
              JFrame jFrame = new JFrame();
              jFrame.getContentPane().add(button);
              jFrame.pack();
              jFrame.setVisible(true);
          }
      }
      -------------------------------------

      "called paint(Graphics g, JComponent c)" will never be printed.

            peterz Peter Zhelezniakov
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: