Java 为什么我们应该使用;空";在对话框中?

Java 为什么我们应该使用;空";在对话框中?,java,dialog,jgrasp,Java,Dialog,Jgrasp,我想知道为什么我们应该在对话框中写“null” str= JOptioPane.showMessageDialog( parentComponent(null), // <-- messageStringExpression, boxTitleString,

我想知道为什么我们应该在对话框中写“null”

str= JOptioPane.showMessageDialog(
                                 parentComponent(null), // <--
                                 messageStringExpression,
                                 boxTitleString,
                                 meeageType);
str=JOptioPane.showMessageDialog(
parentComponent(null),//
为什么我们要在对话框中写“null”

str= JOptioPane.showMessageDialog(
                                 parentComponent(null), // <--
                                 messageStringExpression,
                                 boxTitleString,
                                 meeageType);
如果parentComponent为
null
(又称
parentComponent(null)
),则JDialog依赖于不可见的窗口,并将其放置在外观相关的位置,如屏幕中心

我能写点别的吗

当然,你可以在那里添加任何你想要的组件,比如JButton

例如:

private JButton btn_Save;

btn_Save = new JButton(save);
        btn_Save.setText("Save Configuration");
        btn_Save.setBounds(20, 459, 290, 25);
        btn_Save.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == btn_Save) {
                    if(saveData()){
                        JOptionPane.showMessageDialog(btn_Save, "Event Configuration saved successfully!");
                    }
                    else{
                        JOptionPane.showMessageDialog(btn_Save, "Failed to save Event Configuration!");
                    }
                }
            }
在这种情况下,针对
null
,对话框以按钮
btn\u Save

JOptionPane.showMessageDialog(parentComponent(null),message);       
然后对话框集中在
桌面上

JOptionPane.showMessageDialog(someComponent,message);
然后,以
someComponent

为中心的对话框下面是API文档: