Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:49:03+00:00 2026-06-13T22:49:03+00:00

I want to make text editor with file browser so when I start my

  • 0

I want to make text editor with file browser so when I start my application I want to my program add nodes on JTree so it shows me all files and folders for example in My Documents folder, and to give me ability to access to those files and folders (especially to folders). I tried to figure out how Andrew Thompson did that from this example
but I failed. I managed to create nodes for all files and folders from My Documents using this example
. But thats all, I can’t figure out how to generate nodes for other files and folders when clicking on one of nodes which represent folder.

This is what I’ve done till now:

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;


public class MyTextEditor extends JFrame{

    JTree tree;
    JTabbedPane tabbedPane = new JTabbedPane();
    File myDocumentsFolder = new File("C:/Documents and Settings/User/My Documents");
    File[] listOfFiles = myDocumentsFolder.listFiles();
    String dirTitle = myDocumentsFolder.getName();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(dirTitle);
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);

    public MyTextEditor() {

        tree = new JTree(treeModel);
        tree.setEditable(false);
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        tree.setShowsRootHandles(true);

        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,new JScrollPane(tree),tabbedPane);
        add(splitPane);

        tree.addMouseListener(new MouseAdapter(){
            public void mouseClicked(MouseEvent e){
                for (int i = 0; i < listOfFiles.length; i++) {
                    String nameOfFile = listOfFiles[i].getName();
                    rootNode.add(new DefaultMutableTreeNode(nameOfFile));
                }
            }
        });

    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                MyTextEditor mte = new MyTextEditor();
                mte.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                mte.setPreferredSize(new Dimension(800,600));
                mte.pack();
                mte.setLocationByPlatform(true);
                mte.setVisible(true);
            }
        });
    }

}

Can someone tell me how to generate nodes for all files and folders for specific folder. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:49:03+00:00Added an answer on June 13, 2026 at 10:49 pm

    I use this FileTreeModel for the TreeModel, Outline for the view, and user.dir for the starting directory.

    TreeModel treeModel = new FileTreeModel(
        new File(System.getProperty("user.dir")));
    OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(
        treeModel, new FileRowModel(), true, "User Directory");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a program that's like a simple text editor using Qt
I my application i want to make the text seleected selected using mouse bold..How
I want to make modifications to the middle of a text file using c++,
I want to make an entirely client-side text editor. Unfortunately, dart:io doesn't work client-side
I want to make a text editor which incorporates this sort of effect (see
I want to make simple java program that will insert some text into current
I am trying to make a simple text editor program in C, yet I
I wrote a text editor application which I want to compile statically. I followed
I want to create a text editor where I can make text bold, change
I'm not trying to make a text editor yet. What I want to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.