Answer the question
In order to leave comments, you need to log in
How can I make it so that after pressing the button, it asks the user where to save the file?
private void actionAdd() {
URL verifiedUrl = verifyUrl(addTextField.getText());
if (verifiedUrl != null) {
tableModel.addDownload(new Downloader(verifiedUrl));
addTextField.setText(""); // reset add text field
} else {
JOptionPane.showMessageDialog(this,
"Invalid Download URL", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
Answer the question
In order to leave comments, you need to log in
To show a window with a choice of where to save a file, use JFileChooser.showSaveDialog .
private void actionAdd() {
JFrame parentFrame = new JFrame();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Specify a file to save");
URL verifiedUrl = verifyUrl(addTextField.getText());
if (verifiedUrl != null) {
int userSelection = fileChooser.showSaveDialog(parentFrame);
if (userSelection == JFileChooser.APPROVE_OPTION) {
// что здесь написать,чтобы сохранял файл куда я указал?
tableModel.addDownload(new Download(verifiedUrl));
addTextField.setText(""); // reset add text field
}
} else {
JOptionPane.showMessageDialog(this,
"Invalid Download URL", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question