If JDialog's parent is not visible, when JD is show, where is it's parent.
My question is: if we do not call show method of JDialog's parent,
is there any possibility the parent will be visible?
if you run this code , when the JDialog is show ,it sames that it's parent is MainJFrame("One"), but actually it's parent is MainJFrame("Static").
But we can not see MainJFrame("Static"). Where is it if we do not call show method of it?
Who can tell me is there any possibility the parent will be visible except we call show method( I think maybe Java Swing make it visible under some special condition)?
Thank you.
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JDialog;
publicclass MainJFrameextends javax.swing.JFrame{
public MainJFrame(String title){
setTitle(title);
initComponents();
}
//add a button
privatevoid initComponents(){
twoFrame =new javax.swing.JButton();
twoFrame.setPreferredSize(new Dimension(300,30));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
twoFrame.setText("Two");
twoFrame.addActionListener(new java.awt.event.ActionListener(){
publicvoid actionPerformed(java.awt.event.ActionEvent evt){
twoFrameActionPerformed(evt);
}
});
getContentPane().add(twoFrame);
pack();
}
/**
*button action
*/
privatevoid twoFrameActionPerformed(java.awt.event.ActionEvent evt){
JDialog testDialog =new JDialog(STATIC_FRMAE,"Test",true);//testDialog's parent frame is STATIC_FRMAE, bu STATIC_FRMAE is not visible now.
testDialog.setSize(100,50);
//STATIC_FRMAE.show(); // if we do not call show(), STATIC_FRMAE is still not visible.
testDialog.show();
}
publicstaticvoid main(String[] args){
MainJFrame test =new MainJFrame("One");
test.show();
}
static MainJFrame STATIC_FRMAE =new MainJFrame("Static");
private javax.swing.JButton twoFrame;
}
Message was edited by:
nov_rain

