我正在尝试运行以下代码,但它给了我一个错误
public void addToContainer(JInternalFrame internalframe){
JInternalFrame []allFrames = Jdpmain.getAllFrames();//getting an array of all the frames in my jdesktoppane(jdpmain)
boolean flag=false;
for(int i=0;i<allFrames.length;i++){
JInternalFrame currentFrame = allFrames[i];
if(internalframe.getClass().isInstance(allFrames[i])){
Jdpmain.setSelectedFrame(currentFrame);//if the internal frame already exist it might be under another jinternalframe so, I called this method to bring it to focus
flag=true;
}
if(flag==false){
Jdpmain.add(internalframe); //if an instance of the frame I am adding does not exist in jdesktoppane it should add an instance of it to jdesktoppane
}
}
}
线程“AWT-EventQueue-0”中的异常 java.lang.IllegalArgumentException:非法组件位置 java.awt.Container.addImpl(Container.java:1093)at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:230)at at javax.swing.JDesktopPane.addImpl(JDesktopPane.java:486)at at java.awt.Container.add(Container.java:410)at MyLibrarypackage.MainFrame.addToContainer(MainFrame.java:169)at at MyLibrarypackage.MainFrame.jButton2ActionPerformed(MainFrame.java:148) 在MyLibrarypackage.MainFrame.access $ 100(MainFrame.java:13)at MyLibrarypackage.MainFrame $ 2.actionPerformed(MainFrame.java:62)at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) 在 javax.swing.AbstractButton中的$ Handler.actionPerformed(AbstractButton.java:2341) 在 javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在 javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在 javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在java.awt.Component.processMouseEvent(Component.java:6505)at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)at java.awt.Component.processEvent(Component.java:6270)at java.awt.Container.processEvent(Container.java:2229)at java.awt.Component.dispatchEventImpl(Component.java:4861)at java.awt.Container.dispatchEventImpl(Container.java:2287)at java.awt.Component.dispatchEvent(Component.java:4687)at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) 在 java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) 在java.awt.Container.dispatchEventImpl(Container.java:2273)at java.awt.Window.dispatchEventImpl(Window.java:2713)at java.awt.Component.dispatchEvent(Component.java:4687)at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)at at java.awt.EventQueue.access $ 000(EventQueue.java:101)at java.awt.EventQueue $ 3.run(EventQueue.java:666)at java.awt.EventQueue $ 3.run(EventQueue.java:664)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76) 在 java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:87) 在java.awt.EventQueue $ 4.run(EventQueue.java:680)at java.awt.EventQueue $ 4.run(EventQueue.java:678)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:677)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
如果有人能在这里帮助我,我将很高兴。