Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in Dynaminc tree

Status
Not open for further replies.

deemu

Programmer
Mar 21, 2012
2
DE
i want to create dynamic javatree in applet .and have to perform the(update functions on tree nodes)
Can any one help me to write the coding.
..............

package jtreeevent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;

public class Channel extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
JTree tree;
JTextField jtf ;


public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
DefaultMutableTreeNode top = new DefaultMutableTreeNode("channel");



DefaultMutableTreeNode english = new DefaultMutableTreeNode("English");

top.add(english);

DefaultMutableTreeNode english1 = new DefaultMutableTreeNode("English CH1");

english.add(english1);

DefaultMutableTreeNode english2 = new DefaultMutableTreeNode("English CH2");

english.add(english2);


DefaultMutableTreeNode english3 = new DefaultMutableTreeNode("English CH3");

english.add(english3);



DefaultMutableTreeNode deutsch = new DefaultMutableTreeNode("Deutsch");

top.add(deutsch);

DefaultMutableTreeNode deutsch1 = new DefaultMutableTreeNode("deutsch CH1");

deutsch.add(deutsch1);

DefaultMutableTreeNode deutsch2 = new DefaultMutableTreeNode("deutsch CH2");

deutsch.add(deutsch2);

tree = new JTree(top);


int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;

int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(tree,v,h);


contentPane.add(jsp,BorderLayout.CENTER);
jtf = new JTextField ("",20);
contentPane.add(jtf,BorderLayout.SOUTH);


tree.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me){
doMouseClicked(me);

}

});
}
void doMouseClicked(MouseEvent me)
{
TreePath tp = tree.getPathForLocation(me.getX (), me.getY());
if (tp != null)
jtf.setText(tp.toString());
else
jtf.setText("");

}

}
...............
In this above coding i gave the input and getting the output inside the coding itself. but i need the same result without giving ( for eg :english) in the coding.
the result must be instantly create a dynamic tree form throught the conataining website(update functions on tree nodes).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top