Infolinks In Text Ads

Jun 24, 2010

File Chooser Java applet code example

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame

    public Test()
        super("Simple File Chooser Application");
        chooser = new JFileChooser();
        button = new JButton("show file chooser ...");
        Container contentPane = getContentPane();
        contentPane.setLayout(new FlowLayout());
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
                int state = chooser.showOpenDialog(null);
                File file = chooser.getSelectedFile();
                if(file != null && state == 0)
                    JOptionPane.showMessageDialog(null, file.getPath());
                if(state == 1)
                    JOptionPane.showMessageDialog(null, "Canceled");


    public static void main(String args[])
        JFrame f = new Test();
        f.setBounds(300, 300, 350, 100);
        f.addWindowListener(new WindowAdapter() {

            public void windowClosed(WindowEvent e)


    JFileChooser chooser;
    JButton button;

1 comment:

  1. This is a nice example. But the filechooser is not going inside of the directory. If we are copying the path in the folder name text area, it is opening. No other way to open by double clicking on folder icons.Also i n top row up one level option is there. But down level is not there.


Related Posts Plugin for WordPress, Blogger...