Amir Elsaeed Amir Elsaeed - 27 days ago 9
Java Question

cannot find method setModal(boolean)

why I cann't find setModal() Method

I am working on GUI
I have two jframes
the following code is for a button and supposed to open the other frame
but i get error that say:


cannot find method setModal(boolean)


private void jButton3_actionPerformed(ActionEvent e)
{
HR hr = new HR();
if(f == 1){ // condition
hr.setModal(true); // give me error here ?
hr.setVisible(true);
}else{
jLabel5.setText("You aren't connected...");
}
}


hr.java

import java.awt.Dimension;

import javax.swing.JFrame;

public class HR extends JFrame {
public HR() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize( new Dimension(400, 300) );
}

}

Answer

I am working on GUI I have two jframes

An application should only have a single parent JFrame. Other child windows should be a JDialog and you specify the frame as the parent.

A JDialog DOES have the setModal(...) method.

You create a JDialog the same way you create a JFrame.