Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...