我在Java中实现了另存为对话框,提示用户该文件是否已经存在,并且我希望默认选择否选项。我该怎么做呢?如何使JOptionPane.showConfirmDialog默认没有选中?
这里是我当前的代码:
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();
}
};
我更新了我的答案。 – 2009-09-08 21:04:20