why we should write "null" in dialog boxes ?
If the parentComponent is null
(aka parentComponent(null)
), then the JDialog depends on no visible window, and it's placed in a look-and-feel-dependent position such as the center of the screen.
can I write something else
Sure, you can add there any component you want like JButton, ....
Some example:
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!");
}
}
}
In this case against null
, The dialog centered on button btn_Save