Say i have an object of the JFrame class as frame
I was wondering what is the difference between
JOptionPane.showMessageDialog(null,message)
and
JOptionPane.showMessageDialog(frame,message)
to print something out.Both give the same result and they pop up at the same place.So i was wondering what is really the difference between these two? What happens actually in background differently?
When providing the frame or any other component the option pane will pop up at the middle of the component. However if you are providing null then it will pop up at the middle of your screen.
In your case I guess your Jframe is of your screen size. So if you reduce your frame size and start it at the default location i.e top left corner then you may see the difference.
// the dialog is centered on the desktop
JOptionPane.showMessageDialog(null,message)
// the dialog is centered on the frame
JOptionPane.showMessageDialog(frame,message)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With