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