Solved

2-3 Tree Archiv

Posted on 2004-10-12
15
372 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
ID: 12284861
See DefaultMutableTreeNode
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12284886
0
 

Author Comment

by:mystixs
ID: 12284908
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 6

Expert Comment

by:expertmb
ID: 12284923
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12284925
0
 

Author Comment

by:mystixs
ID: 12284956
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
ID: 12284963
That looks more like a table to me ;-)
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12285023
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
ID: 12285025
have a collection which will hold these data for you.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12285038
0
 

Author Comment

by:mystixs
ID: 12285072
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
ID: 12285139
0
 
LVL 5

Accepted Solution

by:
Naeemg earned 150 total points
ID: 12285215
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
ID: 12290419
?
0
 
LVL 6

Expert Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
Should localization be done inside spring controller 5 32
hibernate example issues from command prompt 10 50
Java syntax, or is it Selenium 6 30
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)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

828 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