0

Hello
I would like to ask how to change button "Open" to "save" when iam using JFileChooser

public void actionPerformed(ActionEvent e) 
    {

        Object zrodlo =e.getSource();

        if(zrodlo == mSave)//zapisywanie pliku 
        {
            JFileChooser fc = new JFileChooser();
            fc.setSelectedFile(new File(fileName));
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            FileNameExtensionFilter filter = new FileNameExtensionFilter(
                        ".txt and .java files", "txt");
                fc.setFileFilter(filter);
            if (fc.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
            {
                File plik = fc.getSelectedFile();
                fileName = plik.getName();
                try 
                {
                    PrintWriter pw = new PrintWriter(plik);
                    Scanner skaner = new Scanner(resultTA.getText());
                    while (skaner.hasNext())
                        pw.println(skaner.nextLine() + "\n");
                    pw.close();
                } 

                catch (FileNotFoundException e1)
                {

                    e1.printStackTrace();
                }

            }
        }



        }
2
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by mateusz.baran1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.