He creado un JOptionPane
y solo tiene dos botones YES_NO_OPTION
.JOptionPane SÍ/No Opciones Confirmar cuadro de diálogo Problema
Después JOptionPane.showConfirmDialog
salga hacia fuera, quiero clic YES BUTTON
seguir abriendo la JFileChooser
y si he hecho clic NO BUTTON
se debe cancelar la operación.
Parece bastante fácil, pero no estoy seguro de cuál es mi error.
Fragmento de código:
if (textArea.getLineCount() >= 1) { //The condition to show the dialog if there is text inside the textArea
int dialogButton = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog (null, "Would You Like to Save your Previous Note First?","Warning",dialogButton);
if (dialogButton == JOptionPane.YES_OPTION) { //The ISSUE is here
JFileChooser saveFile = new JFileChooser();
int saveOption = saveFile.showSaveDialog(frame);
if(saveOption == JFileChooser.APPROVE_OPTION) {
try {
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(saveFile.getSelectedFile().getPath()));
fileWriter.write(textArea.getText());
fileWriter.close();
} catch(Exception ex) {
}
}
wow funcionó! Empecé a usar 'showConfirmDialog' y no lo entendí tan bien, aunque leí el Javadoc. Pero ahora con mi error y tu explicación despejó mucha confusión. Jugaré con esto más y veré qué puedo pensar. ¡¡¡GRACIAS!!! – Sobiaholic
@iMohammad, ¿por qué no lees el tutorial de Swing? El tutorial contiene ejemplos de trabajo, para todas las preguntas que ha estado haciendo en los últimos días. – camickr
Enlace a la sugerencia de camickr: http://docs.oracle.com/javase/tutorial/uiswing/ – ziesemer