如何管理调用另一个 JInternalFrame 的 JInternalFrame? [英] How to manage a JInternalFrame calling another JInternalFrame?
问题描述
我有一个带有此代码的 JDesktopPane.
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();
}
}
我遇到的问题是,当orden"想要弹出另一个 JInternalFrame 时,我使用下一个代码.
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();
}
当我执行该事件超过 2 次时,出现下一个错误:
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
我应该在哪里将新的 JInternalFrame 添加到 DesktopPane?或者到 Orden?,或者我能做些什么来解决这个错误?
Where should i add the new JInternalFrame to the DesktopPane? or to Orden?, or What can i do to fix this error?
推荐答案
如果 searchSupplier 框架已经在桌面上,您就不太可能再次添加它.尝试使用 getParent
来判断是否需要添加框架
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();
}
这篇关于如何管理调用另一个 JInternalFrame 的 JInternalFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!