JOptionPane.showMessageDialog(this, "Text here");
In my experience if you replace the this call with null it will center on the screen. If you replace the this call with panel it should center on the panel. But I've only made this work on a JFrame
, I haven't build a JPanel
yet.