JPanel exposes shared layout manager which is mutable.

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 1.4.0
    • Affects Version/s: 1.3.0
    • Component/s: client-libs
    • None
    • beta
    • x86
    • solaris_2.5

      The flowlayout which is created by a JPanel is shared amongst
      JPanel instances, yet it has properties which may be mutated.
      This is unusual in the GUI classes, as most mutable data structures
      are copied before being returned in public "getter" methods.

      The followwing test case demonstrates the problem:

      import javax.swing.*;
      import java.awt.*;

      public class SimpleFrame1 {

          public static void main(String[] args) {
              JPanel p1 = new JPanel();
              ((FlowLayout)p1.getLayout()).setAlignment(2);
              
              System.out.println("Alignment1: " + ((FlowLayout)p1.getLayout()).getAlignment());

              JPanel p2 = new JPanel();
              ((FlowLayout)p2.getLayout()).setAlignment(0);

              System.out.println("Alignment1: " + ((FlowLayout)p1.getLayout()).getAlignment());
              System.out.println("Alignment2: " + ((FlowLayout)p2.getLayout()).getAlignment());
          }
      }

            Assignee:
            Philip Milne (Inactive)
            Reporter:
            Philip Milne (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: