hi hall, haw can i create a netbeans projects windows like tree in java?
tanks.
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
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...
jopal 0 Unverified User
in netbeans ide there is a projects window:
http://www.netbeans.org/download/flash/netbeans_55/nb_overview/NetBeansOverview.html
how can i program something like that, I mean a tree view.
jopal 0 Unverified User
In netbeans there is a JTree item in Pallete window, thats what I'm looking for .
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
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...)
/* 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
jopal 0 Unverified User
yes, this last answer absolutely respond to my question.
peter_budo tank you very much.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.