944,110 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1532
  • Java RSS
Jul 14th, 2007
0

projects window

Expand Post »
hi hall, haw can i create a netbeans projects windows like tree in java?
tanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Unverified User
jopal is offline Offline
7 posts
since Jul 2007
Jul 14th, 2007
0

Re: projects window

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...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Jul 14th, 2007
0

Re: projects window

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.
Reputation Points: 10
Solved Threads: 0
Unverified User
jopal is offline Offline
7 posts
since Jul 2007
Jul 14th, 2007
0

Re: projects window

In netbeans there is a JTree item in Pallete window, thats what I'm looking for .
Reputation Points: 10
Solved Threads: 0
Unverified User
jopal is offline Offline
7 posts
since Jul 2007
Jul 14th, 2007
0

Re: projects window

Click to Expand / Collapse  Quote originally posted by jopal ...
In netbeans there is a JTree item in Pallete window, thats what I'm looking for .
Well that does not sort your problem if you do not understand how to use tree properly. And what will you do if you get a job in company where they do not use NetBeans and you will benot allowed to instal as they have licence for some other IDE or use only free versions?
So you better learn trees and will give few examples (duno why I do this...)
Java Syntax (Toggle Plain Text)
  1. /* Demonstrate a tree events
  2.  */
  3.  
  4. import java.awt.*;
  5. import javax.swing.*;
  6. import javax.swing.event.*;
  7. import javax.swing.tree.*;
  8.  
  9. class TreeEventDemo
  10. {
  11. JLabel jlab;
  12.  
  13. TreeEventDemo()
  14. {
  15. // Create a new JFrame container
  16. JFrame jfrm = new JFrame("Tree Event Demo");
  17.  
  18. // Use the default border layout manager
  19.  
  20. // give the frame an initial size
  21. jfrm.setSize(200, 200);
  22.  
  23. // terminate program when the user closes the application
  24. jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.  
  26. // create a label that will display the tree selection
  27. jlab = new JLabel();
  28.  
  29.  
  30. /* Begin creating the tree be defining the
  31.   * structure and realtionship of its nodes*/
  32.  
  33. // First, create the root node of the ttree
  34. DefaultMutableTreeNode root = new DefaultMutableTreeNode("Food");
  35.  
  36. /* Next, create twoo subtrees. One contains fruit.
  37.   * The other vegetables.*/
  38.  
  39. // Create the root of the Fruit subtree
  40. DefaultMutableTreeNode fruit = new DefaultMutableTreeNode("Fruit");
  41. root.add(fruit); // add the Fruit node to the tree
  42.  
  43. /* The Fruit subtree has two subtrees on its own.
  44.   * The first is Apples, the second is Pears.*/
  45.  
  46. // Create an Apples subtree
  47. DefaultMutableTreeNode apples = new DefaultMutableTreeNode("Apples");
  48. fruit.add(apples);
  49.  
  50. /* Populate the Apples subtree by adding
  51.   * apple varieties to the Apples subtree*/
  52. apples.add(new DefaultMutableTreeNode("Jonathan"));
  53. apples.add(new DefaultMutableTreeNode("Winesap"));
  54.  
  55. //Create a Pears subtree
  56. DefaultMutableTreeNode pears = new DefaultMutableTreeNode("Pears");
  57. fruit.add(pears);
  58.  
  59. // Populate the Pears subtree
  60. pears.add(new DefaultMutableTreeNode("Barlett"));
  61.  
  62. // Create the root of the Vegetables subtree
  63. DefaultMutableTreeNode veg = new DefaultMutableTreeNode("Vegetables");
  64. root.add(veg);
  65.  
  66. // Populate Vegetables
  67. veg.add(new DefaultMutableTreeNode("Beans"));
  68. veg.add(new DefaultMutableTreeNode("Corn"));
  69. veg.add(new DefaultMutableTreeNode("Potatoes"));
  70. veg.add(new DefaultMutableTreeNode("Rice"));
  71.  
  72. /* Now, create a JTree that uses the structure
  73.   * defined by the preceding statements*/
  74. JTree jtree = new JTree(root);
  75.  
  76. // Allow the tree to be edited so that model events can be generated
  77. jtree.setEditable(true);
  78.  
  79. //Set the tree selection mode to single selection
  80. TreeSelectionModel tsm = jtree.getSelectionModel();
  81. tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  82.  
  83. // Finally, wrap the tree in scroll pane
  84. JScrollPane jscrlp = new JScrollPane(jtree);
  85.  
  86. // Listen for tree expansion events
  87. jtree.addTreeExpansionListener(new TreeExpansionListener()
  88. {
  89. public void treeExpanded(TreeExpansionEvent tse)
  90. {
  91. // Get the path to the expansion point
  92. TreePath tp = tse.getPath();
  93.  
  94. // Display the node
  95. jlab.setText("Expansion: " + tp.getLastPathComponent() );
  96. }
  97.  
  98. public void treeCollapsed(TreeExpansionEvent tse)
  99. {
  100. // Get the path to the expansion point
  101. TreePath tp = tse.getPath();
  102.  
  103. // Display the node
  104. jlab.setText("Collapse: " + tp.getLastPathComponent() );
  105. }
  106. });
  107.  
  108. // Listen for tree selection events
  109. jtree.addTreeSelectionListener(new TreeSelectionListener()
  110. {
  111. public void valueChanged(TreeSelectionEvent tse)
  112. {
  113. // Get the path to the selection
  114. TreePath tp = tse.getPath();
  115.  
  116. //Display the selected node
  117. jlab.setText("Selection event: " +tp.getLastPathComponent() );
  118. }
  119. });
  120.  
  121. // Listen for tree model events.Notice that the listener is registered with tree model
  122. jtree.getModel().addTreeModelListener(new TreeModelListener()
  123. {
  124. public void treeNodesChanged(TreeModelEvent tse)
  125. {
  126. // Get the path to the change
  127. TreePath tp = tse.getTreePath();
  128.  
  129. // Display the Path
  130. jlab.setText("Model change path: " + tp);
  131. }
  132.  
  133. /* Empty implementations of the remaining TreeModelEvent
  134.   * methods. Implement these if your application
  135.   * needs to handle these actions*/
  136. public void treeNodesInserted(TreeModelEvent tse){}
  137. public void treeNodesRemoved(TreeModelEvent tse){}
  138. public void treeStructureChanged(TreeModelEvent tse){}
  139. });
  140.  
  141. // Add the tree and label to the content pane
  142. jfrm.getContentPane().add(jscrlp, BorderLayout.CENTER);
  143. jfrm.getContentPane().add(jlab, BorderLayout.SOUTH);
  144.  
  145. // Display the frame
  146. jfrm.setVisible(true);
  147. }
  148.  
  149. public static void main(String[] args)
  150. {
  151. SwingUtilities.invokeLater(new Runnable()
  152. {
  153. public void run()
  154. {
  155. new TreeEventDemo();
  156. }
  157. });
  158. }
  159. }

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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Jul 14th, 2007
0

Re: projects window

yes, this last answer absolutely respond to my question.
peter_budo tank you very much.
Reputation Points: 10
Solved Threads: 0
Unverified User
jopal is offline Offline
7 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: fail to load Main-class manifest attribute from ......problem
Next Thread in Java Forum Timeline: plz help me in writing an alternate..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC