Results 1 to 4 of 4
  1. #1
    nehaa's Avatar
    nehaa is offline Member
    Join Date
    Jan 2009
    Posts
    35
    Rep Power
    0

    Thumbs up BROWSING and ATTACHING MORE THAN ONE FILES IN JAVA

    :)

    KINDLY Help me with a code for browsing i.e.on clicking BROWSE button , window should appear from which any file on local system can be selected.
    and attaching i.e. on clicking ATTACH button selected file should be attached in report so that user can see the attached file
    eg As in yahoo or gmail we can browse and attach files which can be opened by user.
    Thanks For Valuable Suggestions In Advance :)

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    6

    Default

    /*this is how you select a file assuming your requirement to be swing based gui application, attaching the file will depend upon the apis supported by the reporting tool you are using*/

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class FileSelectionDialog extends JFrame implements ActionListener{
    private String _selectedFileName;

    private JButton _btnSelectFile;

    public FileSelectionDialog(){
    _btnSelectFile=new JButton("Select File");
    setLayout(null);
    _btnSelectFile.setBounds(10,10,100,30);
    add(_btnSelectFile);
    setSize(200,200);
    setVisible(true);
    _btnSelectFile.addActionListener(this);
    }

    public static void main(String args[]){
    new FileSelectionDialog();
    }

    public void actionPerformed(ActionEvent e){
    JFileChooser jf=new JFileChooser();
    jf.showOpenDialog(this);
    File file=jf.getSelectedFile();
    String fname=file.getName();
    System.out.println("File selected::"+fname);
    }
    }
    Last edited by dswastik; 01-23-2009 at 09:53 AM.

  3. #3
    nehaa's Avatar
    nehaa is offline Member
    Join Date
    Jan 2009
    Posts
    35
    Rep Power
    0

    Default

    Thanks for your valuable suggestion.
    I want to save the attached file like a document.
    Thankyou

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    6

Similar Threads

  1. Attaching the Java documentation
    By Eranga in forum NetBeans
    Replies: 11
    Last Post: 08-09-2010, 05:17 AM
  2. [SOLVED] Attaching a mouseListener to a TreeViewer
    By xcallmejudasx in forum New To Java
    Replies: 1
    Last Post: 11-10-2008, 08:38 PM
  3. Attaching a drop-down box within a view(not toolbar)
    By xcallmejudasx in forum Eclipse
    Replies: 1
    Last Post: 10-28-2008, 07:59 PM
  4. [SOLVED] Attaching/Including extra package
    By Eranga in forum NetBeans
    Replies: 16
    Last Post: 07-01-2008, 11:25 AM
  5. conversion of java .class files to .java files
    By kotturupraveen in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •