Java JMenuBar selectSaveFile(JMenuBar menuBar)

Here you can find the source of selectSaveFile(JMenuBar menuBar)

Description

select Save File

License

Open Source License

Declaration

public static String selectSaveFile(JMenuBar menuBar) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import javax.swing.JFileChooser;

import javax.swing.JMenuBar;

public class Main {
    public static String selectSaveFile(JMenuBar menuBar) {

        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle("Specify a file to save");

        int userSelection = fileChooser.showSaveDialog(menuBar);

        if (userSelection == JFileChooser.APPROVE_OPTION) {
            File fileToSave = fileChooser.getSelectedFile();
            System.out.println("Save as file: " + fileToSave.getAbsolutePath());
            return fileToSave.getAbsolutePath();
        }/*from w w w  .  j  a v a2  s  . c o m*/
        return "";
    }
}

Related

  1. getMenuItem(JMenuBar menu, String text)
  2. launch(String title, JComponent component, JMenuBar menuBar)
  3. menu(String text, char mnemonic, JMenuBar menuBar)
  4. pushMenu(JMenuBar jmenubar, String[][] menus)
  5. selectMenuItem(JMenuBar menuBar, Action action, boolean selected)