At this line in the code below:
win.setVisible(true);
it stops with a NullPointerException. It seems to work OK if I put the
canvas straight into a JFrame or Frame.
----------
Exception in thread "main" java.lang.NullPointerException: peer
at sun.awt.windows.WCanvasPeer.create(Native Method)
<snip 18 lines>
at javax.swing.JComponent.setVisible(JComponent.java:1885)
at AnimationWindow.main(AnimationWindow.java:30)
----------
// comments removed in this sample
import java.awt.*;
import javax.swing.*;
public class AnimationWindow extends JInternalFrame {
Canvas cvs;
public AnimationWindow() {
super("Pendula", true, true, true, true);
cvs = new Canvas();
getContentPane().add(cvs);
setSize(300, 300);
}
public static void main(String[] a) {
JFrame frame = new JFrame();
JDesktopPane desktop = new JDesktopPane();
AnimationWindow win = new AnimationWindow();
desktop.add(win);
win.setVisible(true);
frame.setContentPane(desktop);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
----------
Any ideas?
Stewart.
--
My e-mail is valid but not my primary mailbox. Please keep replies on the
'group where everyone may benefit.
<snipped the code example>
> Any ideas?
Yep. Canvas is a heavyweight component, but a JInternalFrame is a
lightweight one. I'd guess the problem you're seeing is a symptom of that.
Use a JPanel, or any other class derived from JComponent, instead of the
Canvas and the problem should go away.
Vil.
--
Vilya Harvey
vi...@lineone.net
http://website.lineone.net/~vilya
Thanks. I've ended up subclassing JComponent and making this the whole
content pane.