-
Bug
-
Resolution: Fixed
-
P3
-
1.0
-
1.0.1
-
sparc
-
solaris_2.4
-
Not verified
If you create a Dialog object and call pack() on it before calling
pack() or show() on it's parent Frame, then the program will exit with
a NullPointerException:
java.lang.NullPointerException
at sun.awt.motif.MComponentPeer.<init>(MComponentPeer.java:78)
at sun.awt.motif.MCanvasPeer.<init>(MCanvasPeer.java:32)
at sun.awt.motif.MPanelPeer.<init>(MPanelPeer.java:30)
at sun.awt.motif.MDialogPeer.<init>(MDialogPeer.java:39)
at sun.awt.motif.MToolkit.createDialog(MToolkit.java:104)
at java.awt.Dialog.addNotify(Dialog.java:78)
at java.awt.Window.pack(Window.java:80)
at DialogTest.<init>(DialogTest.java:13)
at DialogTest.main(DialogTest.java:27)
[note: this is only really a problem with applications since applets
already have their
----------------------------------------------------------
import java.awt.*;
public class DialogTest extends Dialog {
public DialogTest(Frame parent) {
super(parent, "Example Dialog", false);
setLayout(new BorderLayout());
add("North", new Label("This is a Simple dialog", Label.CENTER));
Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(new Button("OK"));
add("South", panel);
pack();
}
public boolean handleEvent(Event event) {
switch(event.id) {
case Event.WINDOW_DESTROY:
hide();
return true;
}
return super.handleEvent(event);
}
public static void main(String args[]) {
Frame frame = new Frame();
frame.setLayout(new FlowLayout());
Dialog dialog = new DialogTest(frame);
frame.pack();
frame.show();
}
}
pack() or show() on it's parent Frame, then the program will exit with
a NullPointerException:
java.lang.NullPointerException
at sun.awt.motif.MComponentPeer.<init>(MComponentPeer.java:78)
at sun.awt.motif.MCanvasPeer.<init>(MCanvasPeer.java:32)
at sun.awt.motif.MPanelPeer.<init>(MPanelPeer.java:30)
at sun.awt.motif.MDialogPeer.<init>(MDialogPeer.java:39)
at sun.awt.motif.MToolkit.createDialog(MToolkit.java:104)
at java.awt.Dialog.addNotify(Dialog.java:78)
at java.awt.Window.pack(Window.java:80)
at DialogTest.<init>(DialogTest.java:13)
at DialogTest.main(DialogTest.java:27)
[note: this is only really a problem with applications since applets
already have their
----------------------------------------------------------
import java.awt.*;
public class DialogTest extends Dialog {
public DialogTest(Frame parent) {
super(parent, "Example Dialog", false);
setLayout(new BorderLayout());
add("North", new Label("This is a Simple dialog", Label.CENTER));
Panel panel = new Panel();
panel.setLayout(new FlowLayout());
panel.add(new Button("OK"));
add("South", panel);
pack();
}
public boolean handleEvent(Event event) {
switch(event.id) {
case Event.WINDOW_DESTROY:
hide();
return true;
}
return super.handleEvent(event);
}
public static void main(String args[]) {
Frame frame = new Frame();
frame.setLayout(new FlowLayout());
Dialog dialog = new DialogTest(frame);
frame.pack();
frame.show();
}
}