问题
The "code part 1" below is used for calling UcakListesi(JinternalFrame) from menuItem in MDI application without problem.
I would like to call same UcakListesi(JinternalFrame) from another JinternalFrame using same code however, I get error about "desktopPane.add(nw);" line see code part 2. Can't access main jframe desktopPane form JinternalFrame ..
is there any way call other JinternalFrame from an JinternalFrame but, in the desktopPane of of main Jframe.
sorry for my poor english.
Regards and thank you.
---code part 1---
private void UckListeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
//Uçak listesi penceresi çağrılıyor
UcakListesi nw = UcakListesi.getInstance();
nw.pack();
if (nw.isVisible()) {
} else {
desktopPane.add(nw);
nw.setVisible(true);
}
try {
//açılan internal frame'in max size ile açılması için
nw.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(AnaUygulama.class.getName()).log(Level.SEVERE, null, ex);
}
}
---code part 2---
class PopUpx extends JPopupMenu {
JMenuItem anItem1;
JMenuItem anItem2;
JMenuItem anItem3;
JMenuItem anItem4;
JMenuItem anItem5;
JSeparator anSeparator1;
JSeparator anSeparator2;
JSeparator anSeparator3;
JSeparator anSeparator4;
JMenu yeni;
ActionListener anListener2;
public PopUpx(final String x){
anItem1 = new JMenuItem(x+ " numaralı Uçak için");
anItem2 = new JMenuItem("Detay Bilgiler");
anItem3 = new JMenuItem("Arıza İş Emri Aç");
anItem4 = new JMenuItem("Uçuş Öncesi Servis");
anItem5 = new JMenuItem("Uçuş Sonrası Servis");
anSeparator1 = new JSeparator();
anSeparator2 = new JSeparator();
anSeparator3 = new JSeparator();
anSeparator4 = new JSeparator();
yeni = new JMenu ("Servis İşlemleri");
add(anItem1);
anItem1.setEnabled(false);
add(anSeparator1);
add(anItem2);
anItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
System.out.println(x+" nolu uçağın "+anItem2.getText()+" basıldı");
UcakListesi nw = UcakListesi.getInstance();
nw.pack();
if (nw.isVisible()) {
} else {
//problem is here
desktopPane.add(nw);
nw.setVisible(true);
}
try {
//açılan internal frame'in max size ile açılması için
nw.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(AnaUygulama.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
anItem2.setToolTipText(x+ " numaralı Uçağın Detay Bilgilerine ulaşılır...");
add(anSeparator2);
add(anItem3);
add(anSeparator3);
yeni.add(anItem4);
add(anSeparator4);
add(yeni);
yeni.add(anItem4);
yeni.add(anSeparator4);
yeni.add(anItem5);
}}
回答1:
I found the solution .
for the first class(MainApplication) where your Jframe and JDesktopPane inside place code below
public javax.swing.JDesktopPane getDesktopPane() {
return desktopPane;
}
then use in any JinternalFrame class file like this to call another one(YourJinternalFrame)
YourJinternalFrame nw = YourJinternalFrame.getInstance();
nw.pack();
if (nw.isVisible()) {
} else {
getDesktopPane().add(nw);
nw.setVisible(true);
}
try {
nw.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex);
}
to get only one instance of called JinternalFrame place this code below in the called JinternalFrame(YourJinternalFrame)
private static YourJinternalFrame myInstance;
public static YourJinternalFrame getInstance() {
if (myInstance == null) {
myInstance = new YourJinternalFrame();
}
return myInstance;
Thank me:)
回答2:
First create f1 frame object on f2 button action
F1 f1 = new F1();
Then create a JDesktopPane object like this
JDesktopPane desktopPane = getDesktopPane();
desktopPane.add(f1);//add f1 to desktop pane
f1.setVisible(true);// set the f1 frame visible
Finally if needed dispose the current frame
this.dispose();
来源:https://stackoverflow.com/questions/15598909/is-there-any-way-call-other-jinternalframe-from-an-jinternalframe-but-in-the-de