Note that there are some explanatory texts on larger screens.

plurals
  1. POsave file from filechooser to my courent directory of project
    primarykey
    data
    text
    <p>i want to copy file that filechooser was selected , to my project directory is use this code for my file chooser ,</p> <p>but i cant find any thing to help me to copy or load that file to my project and use to my ui, what am i doing? </p> <p>its my code:</p> <pre><code>@SuppressWarnings("serial") public class FileChooser extends JPanel implements ActionListener { static private final String newline = "\n"; JButton openButton, saveButton; JTextArea log; JFileChooser fc; public FileChooser() { super(new BorderLayout()); log = new JTextArea(5,20); log.setMargin(new Insets(5,5,5,5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); openButton = new JButton("Open a File...", createImageIcon("images/Open16.gif")); openButton.addActionListener(this); saveButton = new JButton("Save a File...", createImageIcon("images/Save16.gif")); saveButton.addActionListener(this); JPanel buttonPanel = new JPanel(); //use FlowLayout buttonPanel.add(openButton); openButton.setBackground(new java.awt.Color(255,255,255)); buttonPanel.add(saveButton); saveButton.setBackground(new java.awt.Color(255,255,255)); add(buttonPanel, BorderLayout.PAGE_START); buttonPanel.setBackground(new java.awt.Color(255,255,255)); add(logScrollPane, BorderLayout.CENTER); } private File file; public void actionPerformed(ActionEvent e) { boolean isOpen=false; //Handle open button action. if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(FileChooser.this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); //This is where a real application would open the file. log.append("Opening: " + file.getName() + "." + newline); isOpen=true; } else { log.append("Open command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); //Handle save button action. } else if (e.getSource() == saveButton &amp;&amp; isOpen) { System.out.println(file.getAbsolutePath()); File file=fc.getSelectedFile(); new File(file.getName(),"./images/" ); System.out.println("--"+file.getName()); log.append("Saving: " + file.getName() + "." + newline); log.setCaretPosition(log.getDocument().getLength()); } } /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = FileChooser.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { UIManager.put("swing.boldMetal", Boolean.FALSE); createAndShowGUI(); } }); } public static void createAndShowGUI() { JFrame frame = new JFrame("FileChooserDemo"); frame.setDefaultCloseOperation(1); frame.add(new FileChooser()); //Display the window. frame.pack(); frame.setVisible(true); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload