Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the location of "JOptionPane.showMessageDialog"

I want to make JOptionPane.showMessageDialog message appear

  • Any place in the screen.
  • Relative to JFrame. (not at the centre of the JFrame)

For example this will display the message at the centre of the JFrame provided as argument thisFrame

 JOptionPane.showMessageDialog(thisFrame, "Your message.");

And this will display the message at the centre of the screen irrelative to any JFrame.

JOptionPane.showMessageDialog(null, "Your message.");
  • what I want is to set the location of the message any place I want

  • what I want is to set the location of the message relative to the JFrame (not at the centre of the JFrame)

How?

like image 283
Saleh Feek Avatar asked Dec 07 '12 09:12

Saleh Feek


1 Answers

What you need is

    final JOptionPane pane = new JOptionPane("Hello");
    final JDialog d = pane.createDialog((JFrame)null, "Title");
    d.setLocation(10,10);
    d.setVisible(true);
like image 80
Neil Wightman Avatar answered Oct 22 '22 21:10

Neil Wightman