I have problem with showing jInternalFrame from another jInternalFrame to JDesktopane, i'm use Netbeans IDE. First show no problem appears but when the jInternalFrame close with dispose() and want to show again error appears.
This is the error message :
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal component position at java.awt.Container.addImpl(Container.java:1093) at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:230) at javax.swing.JDesktopPane.addImpl(JDesktopPane.java:474) at java.awt.Container.add(Container.java:410) at InternalTes.FrameMaster.menuTambahActionPerformed(FrameMaster.java:83) at InternalTes.FrameMaster.access$000(FrameMaster.java:13) at InternalTes.FrameMaster$1.actionPerformed(FrameMaster.java:49) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at 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) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:708) at java.awt.EventQueue$4.run(EventQueue.java:706) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
This is FrameMaster(JInternalFrame) Code :
package InternalTes; /** * * @author Vikar */ public class FrameMaster extends javax.swing.JInternalFrame { /** * Creates new form FrameMaster */ public FrameMaster() { initComponents(); } private static FrameMaster instance; public static FrameMaster getInstance() { if(instance == null){ instance = new FrameMaster(); } return instance; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { btnShowChild = new javax.swing.JButton(); btnShowChild.setText("Show"); btnShowChild.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnShowChildActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(btnShowChild) .addContainerGap(336, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(238, 238, 238) .addComponent(btnShowChild) .addContainerGap(17, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void btnShowChildActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: FrameChild wd = FrameChild.getInstance(); if(wd.isVisible()){ wd.toFront(); }else { Window.jDesktopPane1.add(wd); wd.setVisible(true); } } // Variables declaration - do not modify private javax.swing.JButton btnShowChild; // End of variables declaration }
This is FrameChild(JInternalFrame) Code :
package InternalTes; /** * * @author Vikar */ public class FrameChild extends javax.swing.JInternalFrame { /** * Creates new form input */ public FrameChild() { initComponents(); } private static FrameChild myInstance; public static FrameChild getInstance() { if(myInstance == null){ myInstance = new FrameChild(); } return myInstance; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { btnClose = new javax.swing.JButton(); btnClose.setText("jButton1"); btnClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCloseActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(311, Short.MAX_VALUE) .addComponent(btnClose) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(244, Short.MAX_VALUE) .addComponent(btnClose) .addContainerGap()) ); pack(); }// </editor-fold> private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: dispose(); } // Variables declaration - do not modify private javax.swing.JButton btnClose; // End of variables declaration }
For Window(JFrame), I did not include it here because the code just usual JFrame & JDesktoPane inside. Please Master of java programming here please it's support, this problem make me crazy for a half years. My System Information Project stuck only because of this problem, i have no problem for using unbranched JInternalFrame.
Thanks, Best & Regrads.