【发布时间】:2010-11-26 14:41:54
【问题描述】:
我在 Java 中实现了一个“另存为”对话框,该对话框会提示用户文件是否已存在,并且我希望默认选择“否”选项。我该怎么做?
这是我当前的代码:
JFileChooser chooser = new JFileChooser()
{
public void approveSelection()
{
File selectedFile = getSelectedFile();
if (selectedFile != null && selectedFile.exists( ) )
{
int response = JOptionPane.showConfirmDialog(
this,
"The file " + selectedFile.getName() + " already exists."
+ " Do you want to replace the existing file?",
getDialogTitle(),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (response != JOptionPane.YES_OPTION )
{
return;
}
}
super.approveSelection();
}
};
【问题讨论】:
标签: java swing joptionpane