Ich habe einen Dialog Speichern unter in Java implementiert, der den Benutzer anfragt, ob die Datei bereits existiert und ich möchte, dass die Option Nein standardmäßig ausgewählt wird. Wie mache ich das?Wie wird JOptionPane.showConfirmDialog standardmäßig auf Nein gesetzt?
Hier ist mein aktueller Code:
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();
}
};
ich meine Antwort aktualisiert. –