You are on page 1of 1

Custom Search

Home C C++ C# Java Servlet JSP EJB Struts2 Mail Hibernate Spring Android Design P Quiz Projects Interview Q Comment Forum

Basics of Java

OOPs Concepts

Java String

Java Regex

Exception Handling
Folder Explorer in Java with Source Code ←prev next →

Java Inner classes

Java Multithreading Folder Explorer in Java with Source Code: We can develop Folder Explorer in java with the help of IO Stream,

Java I/O AWT/Swing with event handling. Let's see the code of creating Folder Explorer in java.

Java Networking
import java.io.*;
Java AWT & Events
import java.awt.*;
Java Swing
import java.awt.event.*;
Swing Introduction
import javax.swing.*;
Java JButton
import javax.swing.tree.*;
Java JLabel
/***********************************/
Java JTextField
Java JTextArea class Explorer extends JPanel implements ActionListener

Java JPasswordField {
Java JCheckBox JTextField jtf;

Java JRadioButton JTextArea jta;
Java JComboBox JTree tree; APPLY NOW
Java JTable JButton refresh;
Java JList
CRICOS Provider Code: 00113B

JTable jtb;
Java JOptionPane
JScrollPane jsp;
Java JScrollBar
JScrollPane jspTable;
Java JMenuItem & JMenu
Java JPopupMenu
String currDirectory=null;
Java JCheckBoxMenuItem
Java JSeparator
Java JProgressBar final String[] colHeads={"File Name","SIZE(in Bytes)","Read Only","Hidden"};

Java JTree String[][]data={{"","","","",""}};


Java JColorChooser
Java JTabbedPane /////////////////////////////////
Java JSlider Explorer(String path)
Java JSpinner {
Java JDialog
Java JPanel
jtf=new JTextField();
Java JFileChooser
jta=new JTextArea(5,30);
Java JToggleButton
refresh=new JButton("Refresh");
Java JToolBar
Java JViewport
Java JFrame File temp=new File(path);

Java JComponent DefaultMutableTreeNode top=createTree(temp);


Java JLayeredPane
Java JDesktopPane //if(top!=null)
Java JEditorPane
Java JScrollPane tree=new JTree(top);
Java JSplitPane
Java JTextPane
jsp=new JScrollPane(tree);
Java JRootPane
Using ToolTip
final String[] colHeads={"File Name","SIZE(in Bytes)","Read Only","Hidden"};
Change Title Icon
String[][]data={{"","","","",""}};
Executable Jar File
Digital Watch jtb=new JTable(data, colHeads);

Graphics in swing jspTable=new JScrollPane(jtb);

Displaying Image

Java Swing Apps setLayout(new BorderLayout());

Notepad add(jtf,BorderLayout.NORTH);

Calculator add(jsp,BorderLayout.WEST);

IP Finder add(jspTable,BorderLayout.CENTER);
Word Counter add(refresh,BorderLayout.SOUTH);
URL Source Generator
Folder Explorer tree.addMouseListener(
Puzzle Game new MouseAdapter()
Pic Puzzle Game
{
Tic Tac Toe Game
public void mouseClicked(MouseEvent me)
Online Exam
{
LayoutManagers
doMouseClicked(me);
BorderLayout
}
GridLayout
});
FlowLayout
jtf.addActionListener(this);
BoxLayout
refresh.addActionListener(this);
CardLayout
}
GridBagLayout
GroupLayout ///////////////////////////////

SpringLayout public void actionPerformed(ActionEvent ev)


ScrollPaneLayout {

JavaFX File temp=new File(jtf.getText());

Java Applet DefaultMutableTreeNode newtop=createTree(temp);


if(newtop!=null)
Java Reflection
tree=new JTree(newtop);
Java Date
remove(jsp);
Java Conversion
jsp=new JScrollPane(tree);
Java Collection
setVisible(false);
Java JDBC
add(jsp,BorderLayout.WEST);
Java New Features
tree.addMouseListener(
RMI new MouseAdapter()
Internationalization {
Interview Questions public void mouseClicked(MouseEvent me)
{
doMouseClicked(me);
}
});

setVisible(true);
}
//////////////////////////////

DefaultMutableTreeNode createTree(File temp)


{
DefaultMutableTreeNode top=new DefaultMutableTreeNode(temp.getPath());
if(!(temp.exists() && temp.isDirectory()))
return top;

fillTree(top,temp.getPath());

return top;
}
//////////////////////////////
void fillTree(DefaultMutableTreeNode root, String filename)
{
File temp=new File(filename);

if(!(temp.exists() && temp.isDirectory()))


return;
//System.out.println(filename);
File[] filelist=temp.listFiles();

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


{
if(!filelist[i].isDirectory())
continue;
final DefaultMutableTreeNode tempDmtn=new DefaultMutableTreeNode(filelist[i].getName());
root.add(tempDmtn);
final String newfilename=new String(filename+"\\"+filelist[i].getName());
Thread t=new Thread()
{
public void run()
{
fillTree(tempDmtn,newfilename);
}//run
};//thread
if(t==null)
{System.out.println("no more thread allowed "+newfilename);return;}
t.start();
}//for
}//function
//////////////////////////////
void doMouseClicked(MouseEvent me)
{
TreePath tp=tree.getPathForLocation(me.getX(),me.getY());
if(tp==null) return;
//jtf.setText(tp.toString());
String s=tp.toString();
s=s.replace("[","");
s=s.replace("]","");
s=s.replace(", ","\\");
//s=s.replace(" ","");
//int z=s.lastIndexOf("\"\\\"");
//s="\'"+s; s=s+"\'";
jtf.setText(s);
showFiles(s);
//java.util.StringTokenizer st=new java.util.StringTokenizer(s,",");
//jtf.setText(jtf.getText()+"="+s);

}
////////////////////////////////
void showFiles(String filename)
{
File temp=new File(filename);
data=new String[][]{{"","","",""}};
remove(jspTable);
jtb=new JTable(data, colHeads);
jspTable=new JScrollPane(jtb);
setVisible(false);
add(jspTable,BorderLayout.CENTER);
setVisible(true);

if(!temp.exists()) return;
if(!temp.isDirectory()) return;

//System.out.println(filename);
File[] filelist=temp.listFiles();
int fileCounter=0;
data=new String[filelist.length][4];
for(int i=0; i<filelist.length; i++)
{
if(filelist[i].isDirectory())
continue;
data[fileCounter][0]=new String(filelist[i].getName());
data[fileCounter][1]=new String(filelist[i].length()+"");
data[fileCounter][2]=new String(!filelist[i].canWrite()+"");
data[fileCounter][3]=new String(filelist[i].isHidden()+"");
fileCounter++;
}//for

String dataTemp[][]=new String[fileCounter][4];


for(int k=0; k<fileCounter; k++)
dataTemp[k]=data[k];
data=dataTemp;

//System.out.println(data);
remove(jspTable);
jtb=new JTable(data, colHeads);
jspTable=new JScrollPane(jtb);
setVisible(false);
add(jspTable,BorderLayout.CENTER);
setVisible(true);
}
////////////////////////////////
///////////////////////////////
}
/***********************************/
class ExplorerTest extends JFrame
{

ExplorerTest(String path)
{
super("Windows Exploder - Javatpoint");
add(new Explorer(path),"Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400,400);
setVisible(true);
}

public static void main(String[] args)


{
new ExplorerTest(".");
}
}
/***********************************/

download this example

Next Topic Puzzle Game in Java

← prev next →

Trade with leverage


1:3k
Low spreads. Fast withdrawal. Broker
in Sri-Lanka with FBS. Sign up!

fbs.com OPEN

Please Share

Learn Latest Tutorials

DS PDFBox Ant JMeter jBPM

Javatpoint Services
JavaTpoint offers too many high quality services. Mail us on hr@javatpoint.com, to get more information about given services.

Website Designing
Website Development
Java Development
PHP Development
WordPress
Graphic Designing
Logo
Digital Marketing
On Page and Off Page SEO
PPC
Content Development
Corporate Training
Classroom and Online Training
Data Entry

Training For College Campus


JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at hr@javatpoint.com.
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter

LEARN TUTORIALS OUR WEBSITES OUR SERVICES CONTACT

Learn Java Tutorial Javatpoint.com Website Development Address: G-13, 2nd Floor, Sec-3
Learn C Tutorial Hindi100.com Android Development Noida, UP, 201301, India
Learn C++ Tutorial Lyricsia.com
Website Designing Contact No: 0120-4256464, 9990449935
Learn C# Tutorial Quoteperson.com
Learn PHP Tutorial Hindi-typing.com Digital Marketing Contact Us
Learn HTML Tutorial Shayaree.com Summer Training Subscribe Us
Learn CSS Tutorial Wordcountee.com Privacy Policy
Industrial Training
Learn JavaScript Tutorial Charactercountee.com Sitemap
Learn jQuery Tutorial Jobandplacement.com College Campus Training
Learn Spring Tutorial

© Copyright 2011-2018 www.javatpoint.com. All rights reserved. Developed by SSS IT Pvt Ltd (JavaTpoint)

You might also like