0

it means when I click a button in my JFrame, a JDialog will be shown.I want to ban my JFrame, it won't be touch but still be shown on screen. I use command in my frame:

button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
               MyDialog md=new MyDialog(MyFrame.this);
               MyDialog.setVisible(true);                 
            }
        });

And in class MyDialog extends JDialog:

public MyDialog(MyGUI myGUI) {
    super(myGUI,true);}

Have something wrong in my code? or Have another way to make it? Please help me!!

mKorbel
  • 109,525
  • 20
  • 134
  • 319
My Will
  • 400
  • 4
  • 27
  • 3
    Do you mean to make the dialog [modal](https://en.wikipedia.org/wiki/Modal_window)? Have a look here: http://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html – Cos64 Nov 06 '15 at 18:18
  • I don't see anything wrong your code. You're setting your dialog modal by doing `super(myGUI,true);` already, so what is your question / what isn't working? – Lukas Rotter Nov 06 '15 at 18:20
  • yes, my program still work but not except. My JFrame still can be touched when My JDialog is opened. I don't know the difference between two commands above: new MyDialog(MyFrame.this) and new MyDialog(this). i wonder if itself is reason? – My Will Nov 07 '15 at 06:14

2 Answers2

2

Add this before MyDialog.setVisible(true);:

MyDialog.setModal(true);

EDIT: This has the same effect as the JDialog(Frame owner, boolean modal) constructor that you are already using. Are you sure you aren't already getting a modal dialog?

MNos
  • 520
  • 6
  • 11
  • yes,JDialog and JFrame still work specially. I still can create the different JDialog when I click the button in JFrame. – My Will Nov 07 '15 at 06:19
0

I found my case. I used to some setting for JDialog, and two of them is :

Container con= getContentPane();
con.add(p);

sorry everybody for my pool JAVA. I'm a beginning and I'm trying to increase my knowlegde. Thank you very much!

My Will
  • 400
  • 4
  • 27