这里是下面的代码片段,在这里我想通过设置其父为resultsTablePanel
显示使用JOptionPane.showConfirmDialog()
对话框:'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)
作为第一个参数?
正如JavaDocs所描述的那样,你将它的引用传递给一个Component,它作为对话框的父对象 – MadProgrammer 2014-12-02 19:27:51