加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何设置JOptionPane的位置

发布时间:2020-12-14 05:54:17 所属栏目:Java 来源:网络整理
导读:我正在创建这个JOptionPane JOptionPane.showMessageDialog(this,"File was saved","Save",JOptionPane.INFORMATION_MESSAGE); 但我的JFrame很大,所以它是可滚动的.当我调用此命令时,会在右下角创建一个窗口,我只能看到标题.我怎样才能改变这个JOptionPane的
我正在创建这个JOptionPane
JOptionPane.showMessageDialog(this,"File was saved","Save",JOptionPane.INFORMATION_MESSAGE);

但我的JFrame很大,所以它是可滚动的.当我调用此命令时,会在右下角创建一个窗口,我只能看到标题.我怎样才能改变这个JOptionPane的位置?

解决方法

根据api 1.6:

the first parameter is parentComponent:

Defines the Component that is to be the parent of this dialog box. It is used in two ways: the Frame that contains it is used as the Frame parent for the dialog box,and its screen coordinates are used in the placement of the dialog box. In general,the dialog box is placed just below the component. This parameter may be null,in which case a default Frame is used as the parent,and the dialog will be centered on the screen (depending on the L&F).

因此,没有参数来设置JOptionPane的位置,但您至少可以将null作为第一个参数传递,以确保您的JOptionPane可见且居中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读