3

I have a JDesktopPane with this code.

public class Menu extends JFrame implements ActionListener{
/**
 * Creates new form Portada
 */
public static JDesktopPane desktop;

public JDesktopPane getDesktop() {
    return desktop;
}

public Menu() {
    desktop = new JDesktopPane();
    setContentPane(desktop);

    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    initComponents();
}
}

then i add the new components like this

desktop.add(orden);

and when i want to call them i use

if(e.getSource()==jMenuItem1_1){
        orden.setVisible(true);
        desktop.setSelectedFrame(orden);
        desktop.moveToFront(orden);
        try {
            orden.setSelected(true);
        } catch (PropertyVetoException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }

The problem i get is that when "orden" wants to pop out another JInternalFrame i use the next code.

searchSupplier.setVisible(true);
    Main.getInstance().getPortada().getDesktop().add(searchSupplier);
    Main.getInstance().getPortada().getDesktop()
            .moveToFront(searchSupplier);
    try {
        searchSupplier.setSelected(true);
    } catch (PropertyVetoException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

When I execute the event more than 2 times i get the next error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal component position

Where should i add the new JInternalFrame to the DesktopPane? or to Orden?, or What can i do to fix this error?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Washu
  • 835
  • 1
  • 9
  • 20

1 Answers1

4

If the searchSupplier frame is already on the desktop, it is unlikely that you will able to add it again. Try using getParent to determine if the frame needs to be added

if (searchSupplier.getParent() == null) {
    Main.getInstance().getPortada().getDesktop().add(searchSupplier);
}
searchSupplier.setVisible(true);
Main.getInstance().getPortada().getDesktop().moveToFront(searchSupplier);
try {
    searchSupplier.setSelected(true);
} catch (PropertyVetoException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 2
    There is no way to express my gratitude to you man... If you ever come to Peru I pay you a big meal. Thanks a lot :) – Washu Mar 14 '13 at 21:47
  • 2
    @Washu Hmm, you make me jealous. – Mordechai Mar 14 '13 at 22:19
  • Next time i ask a question you can help me :P I will gladly offer another meal ;) – Washu Mar 14 '13 at 22:29
  • 2
    @Washu If and when you can, help others solve there problems, that is more repayment that I would ever deserve ;) – MadProgrammer Mar 14 '13 at 23:09
  • @MadProgrammer I usually hang out in chatroom because at my current level i can't provide full answers, i help other newbies to find relevant information in the internet that may help them with their questions. I'm always in Java chat :) – Washu Mar 14 '13 at 23:14