gpt4 book ai didi

java - JFolderChooser.showOpenDialog 中的父组件是什么

转载 作者:行者123 更新时间:2023-11-29 07:20:58 25 4
gpt4 key购买 nike

案例一:

JFileChooser myFileChooser;
myFileChooser.showOpenDialog(this); //this = parent Component

案例二:

JFileChooser myFileChooser;
myFileChooser.showOpenDialog(null);

这两种情况的实际区别是什么?

最佳答案

检查 JFileChooser 的 Javadoc

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.

在内部,它尝试使用此 JOptionPane.getWindowForComponent(parent) 使用父窗口获取窗口。依次检查 parent 是否为 null ...

if (parentComponent == null)
return getRootFrame();

如果为空,则根级框架作为父容器返回。使用内部 SwingUtilities.getSharedOwnerFrame()SwingUtilities.getSharedOwnerFrame() 的 javadoc 说......

Returns a toolkit-private, shared, invisible Frame to be the owner for JDialogs and JWindows created with null owners.

关于java - JFolderChooser.showOpenDialog 中的父组件是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4545557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com