gpt4 book ai didi

java - 'JOptionPane.showConfirmDialog() 这里的第一个参数是什么?

转载 作者:行者123 更新时间:2023-11-29 05:13:55 25 4
gpt4 key购买 nike

这是下面的代码片段,我想通过将其父级设置为 resultsTablePanel 使用 JOptionPane.showConfirmDialog() 显示对话框:

public class SearchResultsTablePanel extends JPanel{...}

public class DefaultSearchListener{

private SearchResultsTablePanel resultsTablePanel = null;

public void f(X x) {
int response = JOptionPane.showConfirmDialog(
resultsTablePanel,
"hai",
"Warning", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);

if (response == JOptionPane.NO_OPTION) {
// do something
} else if (response == JOptionPane.YES_OPTION) {
// do something
} else if (response == JOptionPane.CLOSED_OPTION) {
// do something
}
}
}

我的问题:

对于 java swing api JOptionPane.showConfirmDialog(),我是否需要将 resultsTablePanel 作为第一个参数传递?

我是否需要将 JOptionPane.getframeforcomponent(resultsTablePanel) 作为第一个参数传递?

最佳答案

这并不重要。

作为处理的一部分,JOptionPane 在将参数传递给底层 JDialog 之前调用参数上的 getWindowForComponent(这稍微更通用一些).

至于隐含的问题“到底有什么区别?”,这与模态有关。在这里,我建议您阅读 Oracle's guide to modality .

JOptionPane 使用 JDialog 的默认模态类型,这是上面指南中的应用程序模态。这意味着该对话框将阻止对应用程序中所有窗口的输入,以该对话框作为父级的窗口除外。因此,如果您打开 2 个具有相同父级的对话框 - 您就有麻烦了,但如果其中一个具有另一个作为父级 - 那么子级拥有控制权并且一旦关闭就会将它们转移到他们的父级。

关于java - 'JOptionPane.showConfirmDialog() 这里的第一个参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27256751/

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