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

JPanel exposes shared layout manager which is mutable.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • 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());
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: