Solved

2-3 Tree Archiv

Posted on 2004-10-12
15
369 Views
Last Modified: 2010-03-31
Hello!

I'm a student andi have a little problem with my homework. we have to build a small archiv for example mp3 or doc files..... I have my gui ready and now i have a small problem, i have to develop a 2-3 tree. The tree isn't the problem. The Problem is, how can i insert the values in the tree? That the informations about file don't get lose. and how can i display the informations on the gui? give it at swing method like "excel-look"? How can i change the order?

Thank you

Best regards
mystixs
0
Comment
Question by:mystixs
  • 6
  • 5
  • 3
  • +1
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
See DefaultMutableTreeNode
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
0
 

Author Comment

by:mystixs
Comment Utility
Has everyone an example? for the tree or for displaying the data. it can be another program, but with a small "look-in" the program.
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
0
 

Author Comment

by:mystixs
Comment Utility
I have already seen those tree's. But i mean an tree in the background for sorting the display data. the data should display like the following schedule:


---------------------------------------------------
|File1         |Date               |Time      |Title|
---------------------------------------------------
|File2         |Date               |Time      |Title|
---------------------------------------------------
|File3         |Date               |Time      |Title|
---------------------------------------------------
|File4         |Date               |Time      |Title|
---------------------------------------------------
|File5         |Date               |Time      |Title|
---------------------------------------------------

Do you know, what i mean?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
That looks more like a table to me ;-)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:expertmb
Comment Utility
its not a tree , its table
>>But i mean an tree in the background for sorting the display data. have a collection which will hold these data for you.
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
have a collection which will hold these data for you.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
0
 

Author Comment

by:mystixs
Comment Utility
extpertmb, i would be nice, when you send me the data or have you the posibilty to upload the on a websever? that a can download me the data?
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
0
 
LVL 5

Accepted Solution

by:
Naeemg earned 150 total points
Comment Utility
use the following code according to ur requirements

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.ImageIcon;
import java.net.URL;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;

public class Tree extends JFrame {
    //private JEditorPane htmlPane;
    //private static boolean DEBUG = false;
    //private URL helpURL;

    public Tree() {
        //super("TreeIconDemo");

        //Create the nodes.
        DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
        createNodes(top);

        //Create a tree that allows one selection at a time.
        final JTree tree = new JTree(top);
        tree.getSelectionModel().setSelectionMode
                (TreeSelectionModel.SINGLE_TREE_SELECTION);


        //Create the scroll pane and add the tree to it.
        JScrollPane treeView = new JScrollPane(tree);


        //Add the scroll panes to a split pane.
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPane.setTopComponent(treeView);
        splitPane.setPreferredSize(new Dimension(500, 300));

        //Add the split pane to this frame.
        getContentPane().add(splitPane, BorderLayout.CENTER);
            tree.setShowsRootHandles( true );
    }



    private void createNodes(DefaultMutableTreeNode top) {
        DefaultMutableTreeNode category = null;
        DefaultMutableTreeNode book = null;

        category = new DefaultMutableTreeNode("Books for Java Programmers");
        top.add(category);

        //original Tutorial
        book = new DefaultMutableTreeNode("The Java Tutorial: Object-Oriented Programming for the Internet");
        category.add(book);

        //Tutorial Continued
        book = new DefaultMutableTreeNode("The Java Tutorial Continued: The Rest of the JDK");
        category.add(book);

        //JFC Swing Tutorial
        book = new DefaultMutableTreeNode("The JFC Swing Tutorial: A Guide to Constructing GUIs");
        category.add(book);

        //Arnold/Gosling
        book = new DefaultMutableTreeNode("The Java Programming Language");
        category.add(book);

        //FAQ
        book = new DefaultMutableTreeNode("The Java FAQ");
        category.add(book);

        //Chan/Lee
        book = new DefaultMutableTreeNode("The Java Class Libraries: An Annotated Reference");
        category.add(book);

        //Threads
        book = new DefaultMutableTreeNode("Concurrent Programming in Java: Design Principles and Patterns");
        category.add(book);

        category = new DefaultMutableTreeNode("Books for Java Implementers");
        top.add(category);

        //VM
        book = new DefaultMutableTreeNode("The Java Virtual Machine Specification");
        category.add(book);

        //Language Spec
        book = new DefaultMutableTreeNode("The Java Language Specification");
        category.add(book);
    }



    public static void main(String[] args) {
        JFrame frame = new Tree();

        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        frame.pack();
        frame.setVisible(true);
    }
}

//Naeem Shehzad Ghuman
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
?
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
strange. moderator/venabili can you plz look into such questions.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now