EVALUATION
The problem happens with a pure AWT test.
import java.awt.*;
import javax.swing.*;
public class LocationOnScreenTestAWT {
public static void main (String ... args) {
Frame f = new Frame();
Panel panel = new Panel();
// setBounds() invoaction leads to different results for the label location.
f.setBounds(0, 0, 100, 100);
f.add(panel);
Label js1 = new Label("label 1");
Label js2 = new Label("label 2");
panel.add(js1);
panel.add(js2);
f.setVisible(true);
Point p = js2.getLocationOnScreen();
while (true) {
try {
Point tp = js2.getLocationOnScreen();
if (p.getX()!=tp.getX() || p.getY()!=tp.getY()) {
System.err.println("Location on screen: " + js2.getLocationOnScreen());
p = tp;
}
} catch (Exception e) {
System.err.println(e.getMessage());
continue;
}
}
}
}
=====
Output:
Location on screen: java.awt.Point[x=26,y=55]
Location on screen: java.awt.Point[x=51,y=55]
|
EVALUATION
I have added Thread.sleep(1000) before invocation of getLocationOnScreen()
$ /export/jdk/jdk1.7.0_05b03/bin/java bug5012888
pinner2.getLocationOnScreen() 1:java.awt.Point[x=5,y=75]
< === 1000
pinner2.getLocationOnScreen() 2:java.awt.Point[x=30,y=75]
pinner2.getLocationOnScreen() 2:java.awt.Point[x=30,y=75]
Looks like we have a time gap before shoiwing the component then we do not throw IllegalComponentStateException.
|