(Java) How can I save multiple files at the same time in Jfilechooser from JList?

做~自己de王妃 提交于 2019-12-24 19:46:22

问题


Picture Purpose

I am customizing an Java App for personal use. This App can make many midi files in Java. I would like to SAVE many files at the same time from Jlist. I already could select many files in one time.

(I already changed below)

public interface ListSelectionModel { int MULTIPLE_INTERVAL_SELECTION
> = 2; }

Problems I can’t save many files at the same time from list (JList).

My idea I am afraid I don’t have good idea. I am not good at Java. I researched this problem in Google and books. I expect i need to use code as below.

idea(1)

File[] files = getSelectedFiles();

idea(2)

Zip system

(Original cord)

/**
 * Save File Dialog
 */
private class MidiFileChooser extends JFileChooser {
    {
        setFileFilter(new FileNameExtensionFilter("MIDI sequence (*.mid)", "mid"));
    }
    /**
     * Save File Action
     */
    public Action saveMidiFileAction = getModel().new SelectedSequenceAction(
        "Save",
        "Save selected MIDI sequence to file - Save Midi to File"
    ) {
        @Override
        public void actionPerformed(ActionEvent event) {
            PlaylistTableModel playlistModel = getModel();
            SequenceTrackListTableModel sequenceModel = playlistModel.getSelectedSequenceModel();
            String fn = sequenceModel.getFilename();
            if( fn != null && ! fn.isEmpty() ) setSelectedFile(new File(fn));
            if( showSaveDialog((Component)event.getSource()) != JFileChooser.APPROVE_OPTION ) return;
            File f = getSelectedFile();
            if( f.exists() ) {
                fn = f.getName();
                if( ! confirm("Overwrite " + fn + " ?\n" + fn + " is OK?") ) return;
            }
            try ( FileOutputStream out = new FileOutputStream(f) ) {
                out.write(sequenceModel.getMIDIdata());
                sequenceModel.setModified(false);
                playlistModel.fireSequenceModified(sequenceModel, false);
            }
            catch( IOException ex ) {
                ex.printStackTrace();
                showError( ex.getMessage() );
            }
        }
    };

来源:https://stackoverflow.com/questions/48498181/java-how-can-i-save-multiple-files-at-the-same-time-in-jfilechooser-from-jlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!