作者:huai | 来源:互联网 | 2024-10-08 10:50
我有一个带有此代码的JDesktopPane.publicclassMenuextendsJFrameimplementsActionListener{***Createsnewf
我有一个带有此代码的JDesktopPane.
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();
}
}
然后我像这样添加新组件
desktop.add(orden);
当我想给他们打电话时
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();
}
}
我得到的问题是,当“ orden”想要弹出另一个JInternalFrame时,我将使用下一个代码.
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();
}
当我执行事件超过2次时,出现下一个错误:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal component position
我应该在哪里将新的JInternalFrame添加到DesktopPane?或到Orden ?,或该如何解决此错误?
解决方法:
如果searchSupplier框架已经在桌面上,则不太可能再次添加它.尝试使用getParent确定是否需要添加框架
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();
}