简体   繁体   中英

cannot find method setModal(boolean)

Why can't I call the setModal() method?

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

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) );
    }

}

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 .

JFrame class has no setModal(boolean) method.. refer to the doc here

therefore you CAN NOT invoke that method, your HR class must instead have defined that method... but I see in the update that actually the HR class is not defining it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM