title image


Smiley Beispiel
package testarea;



import java.awt.Container;

import java.awt.event.WindowAdapter;

import java.io.File;



import javax.swing.*;

import javax.swing.filechooser.FileSystemView;

import javax.swing.tree.DefaultMutableTreeNode;



public class FileSystemFrame extends JFrame {

    public FileSystemFrame() {

        Container c = getContentPane();



        c.setLayout(null);



        JTree tree = getTree();

        tree.setCellRenderer(new TreeRenderer());

        JScrollPane scroll = new JScrollPane(tree);

        scroll.setBounds(10, 10, 400, 400);

        c.add(scroll);



        addWindowListener(new WindowAdapter() {

            public void windowClosing(java.awt.event.WindowEvent e) {

                System.exit(0);

            };

        });



        setSize(450, 450);

        setVisible(true);

    }



    private JTree getTree() {

        final FileSystemView fsv = FileSystemView.getFileSystemView();

        File[] fs = fsv.getHomeDirectory().listFiles();



        File t;

        DefaultMutableTreeNode root = new DefaultMutableTreeNode(fsv

                .getHomeDirectory());

        DefaultMutableTreeNode temp;

        for (int i = 0; i < fs.length; i++) {

            if (!fsv.isFileSystem(fs[i])) {

                t = fs[i];

                temp = new DefaultMutableTreeNode(t);

                root.add(temp);



                File[] ts = t.listFiles();

                if (ts != null) {

                    for (int j = 0; j < ts.length; j++) {

                        if (fsv.isDrive(ts[j])) {

                            System.out.println(ts[j]);

                        }



                        temp.add(new DefaultMutableTreeNode(ts[j]));

                    }

                }

            }

        }



        return new JTree(root);

    }



    public static void main(String[] args) {

        new FileSystemFrame();

    }



}



geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: