Duplicate :
|
Name: skT45625 Date: 05/08/2000 java version "1.2" HotSpot VM (1.0fcs, mixed mode, build E) A class may extend a Container class, hold a private member of the superclass to store the components and override the relevant methods. (This is excatly what VisualCafe is doing with its BorderPanel class). Initiating such class and assigning several components which cannot get the focus will lead to a NullPointerException in WWindowPeer.setDefaultFocus() I think the reason is that in WWindowPeer.setDefaultFocus() the native method getContainerElement() is called instead of Container.getComponent(). 1.) Run the below program. 2.) Sample: ======================================== import java.awt.Component; import java.awt.Frame; import java.awt.Label; import java.awt.Panel; public class Test extends Panel { private Panel panel; public Test() { panel = new Panel(); super.add(panel); } public int getComponentCount() { return panel.getComponentCount(); } public Component getComponent(int i) { return panel.getComponent(i); } protected void addImpl(Component comp, Object constraints, int index) { if (comp == panel) super.addImpl(comp, constraints, index); else panel.add(comp, constraints, index); } public static void main(String[] args) { Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); Label label4 = new Label(); Test test = new Test(); test.add(label1); test.add(label2); test.add(label3); test.add(label4); Frame frame = new Frame(); frame.add(test); frame.setVisible(true); } } 3.) Exception: Exception occurred during event dispatching: java.lang.NullPointerException at sun.awt.windows.WWindowPeer.setDefaultFocus(WWindowPeer.java:149) at sun.awt.windows.WWindowPeer.setDefaultFocus(WWindowPeer.java:154) at sun.awt.windows.WWindowPeer.setDefaultFocus(WWindowPeer.java:124) at sun.awt.windows.WActiveEvent.dispatchImpl(Native Method) at sun.awt.windows.WActiveEvent.dispatch(WActiveEvent.java:41) at java.awt.EventQueue.dispatchEvent(EventQueue.java:256) at java.awt.EventDispatchThread.run(EventDispatchThread.java:68) ------------------- Reproducable in 1.3rc3 also ###@###.### 2000-05-08 (Review ID: 104561) ======================================================================