How to manage a JInternalFrame calling another JInternalFrame?

左心房为你撑大大i 提交于 2019-12-23 18:32:00

问题


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?


回答1:


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();
}


来源:https://stackoverflow.com/questions/15420401/how-to-manage-a-jinternalframe-calling-another-jinternalframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!