Results 1 to 6 of 6

Thread: Java JFileChooser

  1. #1
    Join Date
    Nov 2009
    Posts
    140

    Java JFileChooser

    Hello, I am learning java programming and now I want to know the details about the Java JFileChooser and I am not able to get it. I have check it on internet, but it is not understandable for me. So, if anyone is having details about it then please reply me about it, So I can achieve knowledge about it. So, please help me to achieve it.

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

    Re: Java JFileChooser

    Hello, If you want to show the file chooser then you must need to make use of the method given below:
    Code:
       obj = filechoser.showOpenDialog(owner); 
       obj = filechoser.showSaveDialog(owner); 
       obj = filechoser.showDialog(owner, title);
    Here, you must use the owner in place of the component. It may possible to make use of the null value for the owner value.

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

    Re: Java JFileChooser

    Hello, I think you need to make use of the code below for getting knowledge about the Java JFilechoser. So, make use of it.
    Code:
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing .*;
    import java.awt .*;
    import java.awt .*;
    import java.io. *;
     
         Public class FileChooser extends JFrame implements ActionListener{
        
         private JButton b1 = new JButton("Select a file"); 
         private JTextField t1 = new JTextField("No file loaded!");
         private JPanel panel = new JPanel();
         
         Public FileChooser() 
    {
     
         this.setTitle("JFileChooser");
         this.setSize(500, 100);
         this.setLocationRelativeTo(null);
    
         t1.setEditable(false);
    
         b1.addActionListener(this);
         panel.setBackground(Color.CYAN);
         JPanel pane = new JPanel();
         pane.add(t1);
         pane.add(b1);
         panel.add(Pane);
         this.setContentPane(panel);
         this.setVisible(true);
         }
         
          Public void actionPerformed(ActionEvent evt)
     {
    
         JFileChooser chooser = new JFileChooser();
         chooser.showFileChooserDialog(null); 
         if (chooser.showFileChooserDialog(null) == JFileChooser.APPROVE_OPTION)
    	     {
    	     t1.setText(chooser.getSelectedFile().getAbsolutePath()); 
    	     }
         }
         
     } 
    
    
    and here is the code that call this class from my applet
    
    	if (evt.getActionCommand().equals("File"))
    		{
    		FileChooser = new FileChooser();
    FileChooser.show();
    		}

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Java JFileChooser

    Hello, the class JFileChooser provides following methods:
    • void addActionListener(ActionListener l)
    • void addChoosableFileFilter(FileFilter filter)
    • void approveSelection()
    • void changeToParentDirectory()
    • void ensureFileIsVisible(File f)
    • protected void fireActionPerformed(String command)
    • FileFilter getAcceptAllFileFilter()
    • ActionListener[] getActionListeners()
    • int getApproveButtonMnemonic()
    • String getApproveButtonToolTipText()
    • FileFilter[] getChoosableFileFilters()
    • boolean getControlButtonsAreShown()

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

    Re: Java JFileChooser

    Hello, there is a code for the Java Jfilechooser which I have got from internet. You can make use of it for your purpose.
    Code:
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    
    public class test extends JFrame
     {
      public test() 
    {
        JFileChooser fchoose = new JFileChooser();
        fchoose.setDialogTitle("Choose a file");
        this.getContentPane().add(fchoose);
        fchoose.setVisible(true);
      }
    
      public static void main(String[] args)
     {
        JFrame frm = new test();
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.pack();
        frm.setVisible(true);
      }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Java JFileChooser

    Hello, if you want to make use of the selection of the files then you need to make use of the JFileChooser. It is having following three methods as below:
    1. JFileChooser.CANCEL_OPTION
    2. JFileChooser.APPROVE_OPTION
    3. JFileChooser.ERROR_OPTION

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Anchoring a JFileChooser in a JFrame
    By technika in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 11:27 AM
  3. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM
  4. 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,751,711,069.81626 seconds with 16 queries