파일이 이미 존재하는 경우 사용자에게 묻는 Save As 대화 상자를 Java로 구현했으며 기본적으로 No 옵션을 선택하려고합니다. 어떻게해야합니까?JOptionPane.showConfirmDialog를 만드는 방법은 기본적으로 선택되어 있지 않습니까?
JOptionPane(Object message, int messageType, int optionType,
Icon icon, Object[] options, Object initialValue)
options
이 버튼을 지정
및합니다 (options
값 중 하나를) initialValue
가 기본이 무엇인지 지정
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();
}
};
내 대답을 업데이 트 : –