| | |
projects window
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I absolutely do not understand what you trying to say. If you ask question you better to explain it fully not in one wrong worded sentence...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Jul 2007
Posts: 7
Reputation:
Solved Threads: 0
in netbeans ide there is a projects window:
http://www.netbeans.org/download/fla...sOverview.html
how can i program something like that, I mean a tree view.
http://www.netbeans.org/download/fla...sOverview.html
how can i program something like that, I mean a tree view.
•
•
•
•
In netbeans there is a JTree item in Pallete window, thats what I'm looking for .
So you better learn trees and will give few examples (duno why I do this...)
Java Syntax (Toggle Plain Text)
/* Demonstrate a tree events */ import java.awt.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; class TreeEventDemo { JLabel jlab; TreeEventDemo() { // Create a new JFrame container JFrame jfrm = new JFrame("Tree Event Demo"); // Use the default border layout manager // give the frame an initial size jfrm.setSize(200, 200); // terminate program when the user closes the application jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create a label that will display the tree selection jlab = new JLabel(); /* Begin creating the tree be defining the * structure and realtionship of its nodes*/ // First, create the root node of the ttree DefaultMutableTreeNode root = new DefaultMutableTreeNode("Food"); /* Next, create twoo subtrees. One contains fruit. * The other vegetables.*/ // Create the root of the Fruit subtree DefaultMutableTreeNode fruit = new DefaultMutableTreeNode("Fruit"); root.add(fruit); // add the Fruit node to the tree /* The Fruit subtree has two subtrees on its own. * The first is Apples, the second is Pears.*/ // Create an Apples subtree DefaultMutableTreeNode apples = new DefaultMutableTreeNode("Apples"); fruit.add(apples); /* Populate the Apples subtree by adding * apple varieties to the Apples subtree*/ apples.add(new DefaultMutableTreeNode("Jonathan")); apples.add(new DefaultMutableTreeNode("Winesap")); //Create a Pears subtree DefaultMutableTreeNode pears = new DefaultMutableTreeNode("Pears"); fruit.add(pears); // Populate the Pears subtree pears.add(new DefaultMutableTreeNode("Barlett")); // Create the root of the Vegetables subtree DefaultMutableTreeNode veg = new DefaultMutableTreeNode("Vegetables"); root.add(veg); // Populate Vegetables veg.add(new DefaultMutableTreeNode("Beans")); veg.add(new DefaultMutableTreeNode("Corn")); veg.add(new DefaultMutableTreeNode("Potatoes")); veg.add(new DefaultMutableTreeNode("Rice")); /* Now, create a JTree that uses the structure * defined by the preceding statements*/ JTree jtree = new JTree(root); // Allow the tree to be edited so that model events can be generated jtree.setEditable(true); //Set the tree selection mode to single selection TreeSelectionModel tsm = jtree.getSelectionModel(); tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // Finally, wrap the tree in scroll pane JScrollPane jscrlp = new JScrollPane(jtree); // Listen for tree expansion events jtree.addTreeExpansionListener(new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent tse) { // Get the path to the expansion point TreePath tp = tse.getPath(); // Display the node jlab.setText("Expansion: " + tp.getLastPathComponent() ); } public void treeCollapsed(TreeExpansionEvent tse) { // Get the path to the expansion point TreePath tp = tse.getPath(); // Display the node jlab.setText("Collapse: " + tp.getLastPathComponent() ); } }); // Listen for tree selection events jtree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent tse) { // Get the path to the selection TreePath tp = tse.getPath(); //Display the selected node jlab.setText("Selection event: " +tp.getLastPathComponent() ); } }); // Listen for tree model events.Notice that the listener is registered with tree model jtree.getModel().addTreeModelListener(new TreeModelListener() { public void treeNodesChanged(TreeModelEvent tse) { // Get the path to the change TreePath tp = tse.getTreePath(); // Display the Path jlab.setText("Model change path: " + tp); } /* Empty implementations of the remaining TreeModelEvent * methods. Implement these if your application * needs to handle these actions*/ public void treeNodesInserted(TreeModelEvent tse){} public void treeNodesRemoved(TreeModelEvent tse){} public void treeStructureChanged(TreeModelEvent tse){} }); // Add the tree and label to the content pane jfrm.getContentPane().add(jscrlp, BorderLayout.CENTER); jfrm.getContentPane().add(jlab, BorderLayout.SOUTH); // Display the frame jfrm.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new TreeEventDemo(); } }); } }
The Java Tutorials How to Use Trees
Swing Tutorials JTree
and another one
Last edited by peter_budo; Jul 14th, 2007 at 10:12 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- openGL window forms in c# (C#)
- Projects in C++ (C++)
- Calling function in a child window from main parent window (C#)
- I need window~1.ani (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: fail to load Main-class manifest attribute from ......problem
- Next Thread: plz help me in writing an alternate..
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying page pearl print problem program programming project qt recursion scanner screen scrollbar server set size sms sort spamblocker sql string superclass swing system thread threads time tree variablebinding windows xor






