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

[3468 byte] By [nov_raina] at [2007-11-27 4:51:14]
# 1

When you use a modal dialog it is modal to the entire application. So even though you have two separate frames you will not be able to click on either one of them when the dialog is visible.

a) Run your code that shows both JFrames and click on the button to show the dialog.

b) click on some other window so that all three windows are hidden

c) click on the "One" frame in the task bar. Only the "One" frame will become visible.

d) click on the "Static frame in the task bar. Now the "Static" frame and dialog will show together.

So when you specify the parent when creating a modal dialog the parent is used to control when the dialog gets restored when the parent frame is restored.

I don't know how to make a dialog modal only to a single frame.

camickra at 2007-7-12 10:04:55 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thank you for your help.My question is not about how to make a dialog modal only to a single frame. Think about if we run this code without "STATIC_FRMAE.show();" statement, how to make STATIC_FRMAE visible?
nov_raina at 2007-7-12 10:04:55 > top of Java-index,Desktop,Core GUI APIs...
# 3
Simple, if you want to make the frame visible then use the setVisible(...) method.
camickra at 2007-7-12 10:04:55 > top of Java-index,Desktop,Core GUI APIs...
# 4
:)You sitll misunderstand my means.Just run the code, without modify it (with out call STATIC_FRAME.show ...), if you click the button, is there any possibility the STATIC_FRAME will be visible (It is really possible, and I want to know why)?
nov_raina at 2007-7-12 10:04:55 > top of Java-index,Desktop,Core GUI APIs...