I've an AWTEventListener added using which I get the window instance of a PageDialog. Calling getLocationOnScreen on that window instance throws the following exception:
Exception in thread "Thread-2" java.lang.NullPointerException: null pData
at sun.awt.windows.WComponentPeer.getLocationOnScreen(Native Method)
at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1674)
at java.awt.Component.getLocationOnScreen(Component.java:1652)
This is reproducible only on windows, from 5.0 onwards. Runs fine on solaris/linux.
To reproduce:
Run the below testcase.
Click the button labeled 'Click me' and wait till the page dialog appears. See the command window for the output of the getLocationOnScreen call. If an exception is thrown, bug is reproduced.
import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;
public class GetLocationOnScreenTest implements AWTEventListener {
private static Window w;
private static boolean windowAppeared = false;
public void eventDispatched(AWTEvent event) {
if (event.getID() == WindowEvent.WINDOW_OPENED) {
w = (Window) event.getSource();
windowAppeared = true;
}
}
public static void main(String[] args) {
Toolkit.getDefaultToolkit().addAWTEventListener(
new GetLocationOnScreenTest(), AWTEvent.WINDOW_EVENT_MASK);
Frame f = new Frame();
f.setLayout(new FlowLayout());
f.setSize(200, 200);
Button b = new Button("Click me");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
windowAppeared = false;
new Thread(new Runnable() {
public void run() {
System.out.println("Sleeping");
try { Thread.sleep(5000); } catch (Exception e) {}
if (windowAppeared) {
System.out.println("Location: " + w.getLocationOnScreen());
} else {
System.out.println("Page dialog did not appear");
}
}
}).start();
PrinterJob.getPrinterJob().pageDialog(new PageFormat());
}
});
f.add(b);
f.setVisible(true);
}
}