如何设置"JOptionPane.showMessageDialog"的位置; [英] How to set the location of "JOptionPane.showMessageDialog"

查看:1040
本文介绍了如何设置"JOptionPane.showMessageDialog"的位置;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示JOptionPane.showMessageDialog消息

  • 屏幕上的任何地方.
  • 相对于JFrame. (不在JFrame的中心)

例如,这将在作为参数thisFrame

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

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

这将在屏幕中央显示该消息,而与任何JFrame无关.

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

      我想要的是设置消息相对于JFrame的位置(而不是JFrame的中心)

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

      如何?

      推荐答案

      import javax.swing.JDialog;
      import javax.swing.JPanel;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JButton;
      
      public class CustomDialog extends JDialog {
          private JPanel myPanel = null;
          private JButton yesButton = null;
          private JButton noButton = null;
      
          public CustomDialog(JFrame frame, boolean modal, String myMessage) {
          super(frame, modal);
          myPanel = new JPanel();
          getContentPane().add(myPanel);
          myPanel.add(new JLabel(myMessage));
          yesButton = new JButton("Yes");
          myPanel.add(yesButton);
          noButton = new JButton("No");
          myPanel.add(noButton);
          pack();
          //setLocationRelativeTo(frame);
          setLocation(200, 200); // <--
          setVisible(true);
          }
      }
      

      这篇关于如何设置"JOptionPane.showMessageDialog"的位置;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆