mark philips
mark philips

Reputation: 25

java item listener

i need help regarding the save menu item i have in my menu bar. i have set the code to

private void smActionPerformed(java.awt.event.ActionEvent evt) {


}

but i am unsure what needs to go inbetween the brackets? The gui is a form where poeple fill in there medical record e.g combo box "mr/mrs" textfield "medical problems" etc and when they click file save i would like the user to get a save box (like save as box in word) and the information to be saved in a txt file.

P.S. would it be possible to have the "file type" set to save as a txt file as default.

Upvotes: 1

Views: 387

Answers (2)

Jeff
Jeff

Reputation: 103

Maybe looking at this could help you. I don't fully understand what you need.

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFileChooser.html http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html

Upvotes: 0

BalusC
BalusC

Reputation: 1109132

Use JFileChooser#showSaveDialog() to ask the enduser to select a File.

JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
    File file = fileChooser.getSelectedFile();
    // ...
} else {
    // User pressed cancel.
}

Upvotes: 1

Related Questions