Results 1 to 6 of 6

Thread: Anchoring a JFileChooser in a JFrame

  1. #1
    Join Date
    Nov 2009
    Posts
    680

    Anchoring a JFileChooser in a JFrame

    Hello, I want to Anchor the JFileChooser in a JFrame. So, if anyone is having the program which can simply provide me the details about it, then provide me that. It will be helpful to me. I have searched on internet and not find anything about it. If you know any other sources then please provide me that also.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Anchoring a JFileChooser in a JFrame

    Hello, I don't know it is right or wrong as I have not tested it, But, I have created the code below which can simply provide you the Anchor a JFileChoser in JFrame. So, just make use of it and check whether it is working or not.
    Code:
    Public class FileChooser implements ActionListener
    {
    JFileChooser JFC = new JFileChooser();
    private JFrame Frm;
    Public void actionPerformed(ActionEvent arg0) 
    {
    Frm = new JFrame("Open");
    JFC.setAcceptAllFileFilterUsed(false);
    FileFilter Filter1 = new FileNameExtensionFilter("MP3 File", "mp3");
    FileFilter Filter2 = new FileNameExtensionFilter("WAV File", "wav");
    JFC.addChoosableFileFilter(Filter1);
    JFC.addChoosableFileFilter(Filter2);
    Frm.add(JFC);
    Frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Frm.setSize(new Size(600, 350));
    Frm.setVisible(true);
    }	  
    }

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Anchoring a JFileChooser in a JFrame

    Hello, I think you need to make use of the books below which can help you to get the code about the Anhoring A JFileChoser in a JFrame.
    1. Java: An Introduction to Computer Science and Programming by Walter Savitch
    2. Problem Solving With Java by Elliot B. Koffman and Ursula Wolz
    3. Introduction to Programming Using Java: An Object-Oriented Approach by David M. Arnow and Gerald Weiss
    4. Thinking in Java by Bruce Eckel
    5. Just Java 2 : J2SE 1.5 Edition
    6. Java How to Program Sixth Edition. by Deitel and Deitel
    7. Core Web Programming: Second Edition by Marty Hall
    8. Core Java 2 by Horstmann and Cornell
    9. Java in a Nutshell Fourth Edition by David Flanagan

    Level of the each book increases as per you move to downwards.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Anchoring a JFileChooser in a JFrame

    See, the code below which is using the object of the File class for getting it and solving the problem. So, you also need to do it and solve your problem.
    Code:
    Public void actionPerformed(ActionEvent AE) 
    {
    if (AE.getActionCommand().equals("CancelSelection") ) 
    {
    }
    else
    { 
    File fname = fc.getSelectedFile();
    System.out.System.out.println(fname.getAbsolutePath());
    fname.delete()f.setVisible(false)f.features();
    }
    }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Anchoring a JFileChooser in a JFrame

    In your actionlistener you must make use of the code below which will help you to get the JFIleChooser in a JFame. So, just make use of it and solve the problem.
    Code:
    ActionListener listener = new ActionListener() 
    {
    public void actionPerformed(ActionEvent ae) 
    {
    JFileChooser choser = (JFileChooser)ae.getSource();
    String str = ae.getActionCommand();
    if (str.equals(JFileChooser.APPROVE_SELECTION)) 
    {
    File sfile = choser.getSelectedFile();
    dirname.setText(sfile.getParent());
    filename.setText(sfile.getName());
    }  
    else if (str.equals(JFileChooser.CANCEL_SELECTION)) 
    {
              dirname.setText(" ");
              filename.setText(" ");
    }
    }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: Anchoring a JFileChooser in a JFrame

    Hello, simply make use of the code below for anchoring a JFileChoser in a JFrame. It is simple and you need to make use of the JFileChooser object and solve your problem.
    Code:
    String fname = File.separator+"tmp"; 
    JFileChooser fchooser = new JFileChooser(new File(fname));
    fchooser.showOpenDialog(frame); 
    File set = fchooser.getSelectedFile(); 
    fchooser.showSaveDialog(frame); 
    set = fchooser.getSelectedFile();

Similar Threads

  1. Pass JFrame to actionlistener
    By Freeza 2 in forum Software Development
    Replies: 5
    Last Post: 23-08-2010, 06:30 PM
  2. What is the use of JFrame class?
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 17-02-2010, 10:56 AM
  3. Java JFileChooser
    By D_chapple in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 10:53 PM
  4. JFrame window problem
    By cyber-noob in forum Software Development
    Replies: 2
    Last Post: 09-11-2009, 11:45 AM
  5. Network chooser from a JFileChooser
    By Fenton in forum Networking & Security
    Replies: 5
    Last Post: 12-12-2008, 07:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,694,526.20305 seconds with 16 queries