JFolderChooser.showOpenDialog 中的父组件是什么
案例 1:
JFileChooser myFileChooser;
myFileChooser.showOpenDialog(this); //this = parent Component
案例 2:
JFileChooser myFileChooser;
myFileChooser.showOpenDialog(null);
这两种情况有什么实际区别?
Case 1:
JFileChooser myFileChooser;
myFileChooser.showOpenDialog(this); //this = parent Component
Case 2:
JFileChooser myFileChooser;
myFileChooser.showOpenDialog(null);
What is the practical difference between the two cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 JFileChooser 的 Javadoc
在内部,它尝试使用此
JOptionPane.getWindowForComponent(parent)
来获取使用父级的窗口。依次检查父级是否为空...如果为空,则根级别框架将作为父容器返回。
使用内部
SwingUtilities.getSharedOwnerFrame()
。SwingUtilities.getSharedOwnerFrame()
的 javadoc 说...Checkout the Javadoc for JFileChooser
internally it tries to get a window using the parent using this
JOptionPane.getWindowForComponent(parent)
. Which in turn checks if parent is null or not...If it is null then Root level frame is returned as parent container.
Using the internal
SwingUtilities.getSharedOwnerFrame()
. The javadoc forSwingUtilities.getSharedOwnerFrame()
says...您可以指定父级来确定对话框与哪个组件相关。它将确定对话框的位置(居中,相对于父对话框)。我还猜测该对话框将是模态的,从而阻塞父窗口。
如果指定 null,则显示的对话框将不属于任何组件,我猜它会显示在屏幕的左上角或中心(最后一种更有可能发生,我没有测试过)。
希望这有帮助!
You can specify the parent to determine which component the dialog is related to. It will determine the position of your dialog (centered, relative to the parent). I also guess that the dialog will be modal, thus blocking the parent window.
If you specify null, the dialog shown won't belong to any component, and I guess it will be displayed either at the top left of the screen or at the center (the last being more likely to happen, I have not tested).
Hop this helps !