本文整理汇总了Java中javax.swing.JFileChooser.showSaveDialog方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.showSaveDialog方法的具体用法?Java JFileChooser.showSaveDialog怎么用?Java JFileChooser.showSaveDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.showSaveDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jButton3ActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// Imprimir
try{
JFileChooser fcPick = new JFileChooser();
int returnVal = fcPick.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fcPick.getSelectedFile();
new MainFrame().setFile(file);
if(file.getName().contains(".txt")){
//writer.writeIt(file, factura.toString());
//new MainFrame().setFile(file);
}else{
//writer.writeIt(file.getPath()+".txt", factura.toString());
}
}
}catch(Exception e){
showMessageDialog(null, "Error: por favor verifique la ruta de su archivo.");
}
}
示例2: saveLevelAs
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void saveLevelAs() {
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Save as...");
fc.setFileFilter(new FileNameExtensionFilter("Pekka Kana 2 Level", "map", "MAP"));
if (Data.currentFile == null) {
fc.setSelectedFile(new File(Settings.EPISODES_PATH));
} else {
fc.setSelectedFile(Data.currentFile);
}
int res = fc.showSaveDialog(frame);
if (res == JFileChooser.APPROVE_OPTION) {
saveLevel(fc.getSelectedFile());
}
}
示例3: jMenuItem11ActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
JFileChooser fileChooser=new JFileChooser();
fileChooser.setDialogTitle("Speciify a file to Save");
int userSelection=fileChooser.showSaveDialog(this);
if(userSelection==JFileChooser.APPROVE_OPTION)
{
File fileToSave=fileChooser.getSelectedFile();
fileToSave.getAbsolutePath();
if(!fileToSave.exists())
{
try {
fileToSave.createNewFile();
} catch (IOException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
paintToPDF(editorPanes.get(tabbedPane.getSelectedIndex()),fileToSave);
}
// TODO add your handling code here:
}
示例4: saveFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String saveFile(Component component, String choosertitle, String startDirectory)
{
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File(startDirectory!=null?".":startDirectory));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showSaveDialog(component) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
return chooser.getSelectedFile().toString();
}
else {
System.out.println("No Selection ");
return null;
}
}
示例5: takeScreenShot
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void takeScreenShot() {
try {
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File(SCREENSHOT_FILE +
"." + SCREENSHOT_FILE_TYPE));
int retVal = fc.showSaveDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
BufferedImage i = new BufferedImage(this.pf.getWidth(),
this.pf.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = i.createGraphics();
this.pf.paint(g2); // paint playfield to buffered image
ImageIO.write(i, SCREENSHOT_FILE_TYPE, file);
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(gui.getParentFrame(),
"screenshot failed (problems with output file?)",
"Exception", JOptionPane.ERROR_MESSAGE);
}
}
示例6: importFileContent
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Returns as a string the content of a chosen file.
* @param dialogTitle
* @return
*/
public String importFileContent(String dialogTitle) {
JFileChooser fileChooser = new JFileChooser();
String filePath;
int userSelection;
fileChooser.setDialogTitle(dialogTitle);
userSelection = fileChooser.showSaveDialog(null);
if (userSelection == JFileChooser.APPROVE_OPTION) {
filePath = fileChooser.getSelectedFile().getAbsolutePath();
// Read file
byte[] encoded;
try {
encoded = Files.readAllBytes(Paths.get(filePath));
return new String(encoded, StandardCharsets.UTF_8);
}
catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
示例7: folderButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void folderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_folderButtonActionPerformed
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
folderField.setText(fc.getSelectedFile().getAbsolutePath());
firePropertyChange("validity", null, null);
}
}
示例8: doStartRecordingAndSaveAVIAs
import javax.swing.JFileChooser; //导入方法依赖的package包/类
synchronized public void doStartRecordingAndSaveAVIAs() {
if (aviOutputStream != null) {
JOptionPane.showMessageDialog(null, "AVI output stream is already opened");
return;
}
JFileChooser c = new JFileChooser(lastFileName);
c.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".avi");
}
@Override
public String getDescription() {
return "AVI (Audio Video Interleave) Microsoft video file";
}
});
c.setSelectedFile(new File(lastFileName));
int ret = c.showSaveDialog(null);
if (ret != JFileChooser.APPROVE_OPTION) {
return;
}
if (!c.getSelectedFile().getName().toLowerCase().endsWith(".avi")) {
String newName = c.getSelectedFile().toString() + ".avi";
c.setSelectedFile(new File(newName));
}
lastFileName = c.getSelectedFile().toString();
if (c.getSelectedFile().exists()) {
int r = JOptionPane.showConfirmDialog(null, "File " + c.getSelectedFile().toString() + " already exists, overwrite it?");
if (r != JOptionPane.OK_OPTION) {
return;
}
}
openAVIOutputStream(c.getSelectedFile(), additionalComments);
}
示例9: renameFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public void renameFile(DownloadListItem item, int row) {
if (item.state == IXDMConstants.COMPLETE) {
showMessageBox(getString("DWN_FINISHED"), getString("DEFAULT_TITLE"), JOptionPane.ERROR_MESSAGE);
} else {
String file, folder;
JFileChooser jfc = XDMFileChooser.getFileChooser(JFileChooser.FILES_ONLY,
new File(item.saveto, item.filename));
if (jfc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
return;
}
file = jfc.getSelectedFile().getName();
folder = jfc.getSelectedFile().getParent();
if (item.mgr != null) {
if (item.mgr.getState() == IXDMConstants.ASSEMBLING) {
showMessageBox(getString("DWN_ASSEMBLING"), getString("DEFAULT_TITLE"), JOptionPane.ERROR_MESSAGE);
} else {
item.mgr.setDestdir(folder);
item.mgr.setFileName(file);
}
}
item.filename = file;
item.saveto = folder;
list.downloadStateChanged();
model.fireTableDataChanged();// model.fireListItemUpdated(row);
}
}
示例10: askOverWrite
import javax.swing.JFileChooser; //导入方法依赖的package包/类
int askOverWrite() {
JFileChooser chooser = MapApp.getFileChooser();
int ok = JOptionPane.NO_OPTION;
while( true ) {
ok = JOptionPane.showConfirmDialog(dialog,
"File exists. Overwrite?",
"Overwrite?",
JOptionPane.YES_NO_CANCEL_OPTION);
if( ok!=JOptionPane.NO_OPTION) return ok;
ok = chooser.showSaveDialog(dialog);
if( ok==JFileChooser.CANCEL_OPTION ) return JOptionPane.CANCEL_OPTION;
if( !chooser.getSelectedFile().exists() ) return JOptionPane.YES_OPTION;
}
}
示例11: showSaveDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected String showSaveDialog(String title, String dir, IOFileFilter filter, File defaultFile) throws Exception {
JFileChooser chooser = new JFileChooser(dir);
chooser.setFileFilter(filter);
chooser.setDialogTitle(title);
if (defaultFile != null) chooser.setSelectedFile(defaultFile);
int returnVal = chooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
return (chooser.getSelectedFile().toString());
}
return (null);
}
示例12: getFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Opens a file from disk.
*
* @param frame
* Parent frame.
* @return Opened file.
*/
public static File getFile(JVDraw frame) {
JFileChooser fc = new JFileChooser("./");
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(new FileNameExtensionFilter(".jvd", "jvd"));
int status = fc.showSaveDialog(frame);
if (status == JFileChooser.OPEN_DIALOG) {
return setExtension(fc.getSelectedFile(), ".jvd");
}
return null;
}
示例13: onClick
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public void onClick(ActionEvent arg0)
{
List<String> v_TableNames = this.getHBase().getTableNames();
if ( JavaHelp.isNull(v_TableNames) )
{
this.getAppFrame().showHintInfo("数据库中不存在表" ,Color.BLUE);
return;
}
File v_SaveFile = new File(this.getHBase().getHBaseIP() + ".txt");
JFileChooser v_FileChooser = new JFileChooser();
v_FileChooser.setSelectedFile(v_SaveFile);
try
{
// 不知道为什么非要sleep一下才再在多次反复打开对话窗口时不出异常,保证每次都能打开对话窗口。
// 测试环境:Mac 10.12.5、Java 1.6、Eclipse 4.3.2
Thread.sleep(10);
}
catch (Exception exce)
{
// Nothing.
}
int v_Result = v_FileChooser.showSaveDialog(this.getAppFrame());
if ( v_Result == JFileChooser.APPROVE_OPTION )
{
v_SaveFile = v_FileChooser.getSelectedFile();
this.writeContents(v_TableNames ,v_SaveFile);
}
}
示例14: saveResults
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static boolean saveResults(String title, String desc) {
lastResults.setTitle(title);
lastResults.setDescription(desc);
JFileChooser fc = getFileChooser();
int ret = fc.showSaveDialog(guiFrame);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
boolean append = false;
if (file.exists()) {
if (!file.isFile()) {
System.err.println("Cannot save results to a directory!");
return false;
}
ret = JOptionPane.showOptionDialog
(guiFrame,
new String[] {
"The file '"+file.getName()+"' already exists!",
"",
"Do you wish to overwrite or append to this file?",
},
"File exists!",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null, new String[] {
"Overwrite",
"Append",
"Cancel",
}, "Cancel");
if (ret == 0) {
append = false;
} else if (ret == 1) {
append = true;
} else {
return false;
}
}
String reason = saveResults(file, append);
if (reason == null) {
return true;
} else {
System.err.println(reason);
}
}
return false;
}
示例15: exportToCSV
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void exportToCSV()
throws IOException
{
final String ENCODING = "UTF-8";
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Export data to CSV file...");
fileChooser.setFileFilter(new FileNameExtensionFilter("CSV Files (*.csv)", "csv"));
int result = fileChooser.showSaveDialog(this.getRootPane().getParent());
if (result != JFileChooser.APPROVE_OPTION)
{
return;
}
File f = fileChooser.getSelectedFile();
FileOutputStream fos = new FileOutputStream(f);
fos.write(new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF } );
// Write header
StringBuilder header = new StringBuilder();
for (int i = 0; i < this.getColumnCount(); i++)
{
String columnName = this.getColumnName(i);
header.append(columnName);
if (i < (this.getColumnCount() - 1))
{
header.append(",");
}
}
header.append("\n");
fos.write(header.toString().getBytes(ENCODING));
// Write rows
for (int row = 0; row < this.getRowCount(); row++)
{
StringBuilder rowBuf = new StringBuilder();
for (int col = 0; col < this.getColumnCount(); col++)
{
rowBuf.append(this.getValueAt(row, col).toString());
if (col < (this.getColumnCount() - 1))
{
rowBuf.append(",");
}
}
rowBuf.append("\n");
fos.write(rowBuf.toString().getBytes(ENCODING));
}
fos.close();
JOptionPane.showMessageDialog(
this.getRootPane().getParent(),
"The data has been exported successfully as CSV to location:\n" +
f.getCanonicalPath(),
"Export successful...", JOptionPane.INFORMATION_MESSAGE);
}