java – 如何设置JOptionPane的位置

前端之家收集整理的这篇文章主要介绍了java – 如何设置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 @R_301_460@. It is used in two ways: the Frame that contains it is used as the Frame parent for the dialog @R_301_460@,and its screen coordinates are used in the placement of the dialog @R_301_460@. In general,the dialog @R_301_460@ 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可见且居中.

猜你在找的Java相关文章