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

JComponent exposes internal Dimension data with setPreferredSize() and friends

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • client-libs



      Name: jl125535 Date: 04/24/2002


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


      A DESCRIPTION OF THE PROBLEM :
      On JComponent, the setPreferredSize() setMaximumSize() and
      setMinimumSize() methods directly store the passed-in
      Dimension object. Subsequent changes to this object will
      affect the JComponent! For example, I've seen code like
      this more than once:

      Dimension d = new Dimension(100, 20);
      label.setPreferredSize(d);
      d.width = 150;
      label2.setPreferredSize(d);

      This will cause both labels to have the same preferred
      size. This is unlike most other Java calls (e.g. the
      setSize() method).

      This should be fixed or, if it's too late to fix it, should
      at least be well-documented.

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

            svioletsunw Scott Violet (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: