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