如何设置JOptionPane的位置 [英] how to set position of JOptionPane

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

问题描述

我正在创建此JOptionPane

JOptionPane.showMessageDialog(this, "File was saved", "Save", 
   JOptionPane.INFORMATION_MESSAGE);

但是我的JFrame很大,因此可以滚动.当我调用此命令时,将在右下角创建一个窗口,并且我只能看到标题.如何更改此JOptionPane的位置?

but my JFrame is big so it is scrollable. When I call this command, a window is created in the bottom right corner and I can only see the header. How I can change the position of this JOptionPane?

推荐答案

根据api 1.6:

第一个参数是 parentComponent :

定义该对话框的父组件.它有两种使用方式:包含它的框架用作对话框的框架父级,并且其屏幕坐标用于对话框的放置中.通常,对话框位于组件的正下方.此参数可以为null,在这种情况下,默认的Frame用作父级,并且对话框将位于屏幕的中心(取决于L& F).

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清晰可见并居中.

So there isn't no parameter to set the position of the JOptionPane, but you could at least pass null as first parameter to be sure your JOptionPane is well visible and centered.

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

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