JAVA中showDialog(),showOpenDialog()参数问题

今天在学习JAVA JFileChooser类下的showOpenDialog中发现这个Component参数不是太明白,经过查找资料最终解决了这个问题。

无论是showOpenDialog,showSaveDialog还是showDialog函数中都有一个Component parent参数问题。

其实这个问题很简单,简单一句话就是这个参数决定你弹出文件选择器的位置

下面是JAVA API文档原解释

The parent argument determines two things: the frame on which the open dialog depends and the component whose position the look and feel should consider when placing the dialog. If the parent is a Frame object (such as a JFrame) then the dialog depends on the frame and the look and feel positions the dialog relative to the frame (for example, centered over the frame). If the parent is a component, then the dialog depends on the frame containing the component, and is positioned relative to the component (for example, centered over the component). If the parent is null, then the dialog depends on no visible window, and it's placed in a look-and-feel-dependent position such as the center of the screen.

翻译后:父参数决定了两件事:打开对话框所依赖的框架和放置对话框时应考虑其外观位置的组件。如果父对象是一个框架对象(例如JFrame),那么该对话框取决于框架和外观,对话框相对于框架的位置(例如,以框架为中心)。如果父元素是一个组件,那么对话框取决于包含该组件的框架,并且相对于该组件定位(例如,以组件为中心)。如果父窗口为空,则对话框依赖于没有可见窗口,并且它被放置在外观和感觉相关的位置,例如屏幕的中心。

parent参数:

null———当前电脑显示器屏幕的中央。

this———当前你编写的程序屏幕中央

如果是你其他的按钮名称就是以这个按钮为中心,弹出的文件选择器。

本人只是一个走在学习JAVA道路上的小菜鸟,哪里有不对的地方,请斧正,谢谢。

  • 18
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值