Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Editable JTree Nodes 

                         

In this section, you will learn  to make JTree editable nodes. For example. . If you want to edit the  name of a  tree node then the following program will  help you a lot.

Program Description:

This program constructs a JTree that contains editable nodes. Firstly, it defines a class  "JTreeEditable".  Here we have used the init() method to create the  nodes  (Root, open, close, save, save as, and exit) of the tree. These nodes are added in a JTree object and we set the editable mode to " true " through the setEditable() method. The init() method adds these components to the JFrame. When you want to edit these components, just double click them and rename them..

setEditable(): 
This method takes a  boolean value that is either a 'true' or a  'false'. When you enter true it becomes editable.

Here is the code of this program:

import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;

public class JTreeEditable extends JFrame {
  DefaultTreeModel treeModel;
  public JTreeEditable() {
    super("Editable Tree Frame");
    setSize(200200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
  
  public void init(){
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode file = new DefaultMutableTreeNode("File");
    DefaultMutableTreeNode open = new DefaultMutableTreeNode("Open")
    DefaultMutableTreeNode save = new DefaultMutableTreeNode("Save")
    DefaultMutableTreeNode saveas = new DefaultMutableTreeNode("Save As")
    DefaultMutableTreeNode exit = new DefaultMutableTreeNode("Exit")
    treeModel = new DefaultTreeModel(root);
    JTree tree = new JTree(treeModel);
    tree.setEditable(true);
    treeModel.insertNodeInto(file,root, 0);
    file.add(open);
    file.add(save);
    file.add(saveas);
    file.add(exit);
    getContentPane().add(tree, BorderLayout.CENTER);
  }
  
  public static void main(String args[]) {
    JTreeEditable st = new JTreeEditable();
    st.init();
    st.setVisible(true);
  }
}

Download this program.

Output this program:

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
validate radio button
Copy One Database Tabl
Access Infotech
drill down using jfree
capture image
Flash Flash tutorials
insert content to text
Photoshop Effects Hole
ready made component o
linked list and window
jQuery To Slide Effect
file input output
WHERE Statement in SQL
convert byte to char
user registration
arithmetic date
java strings
width
define
jQuery To Hide the Div
scwcd
saveOrUpdate faces
login using JSP
spring MVC application
prime numbers
how to create session
com.mysql.jdbc.Driver
Bryce 3d Materials Wat
trusted root certifica
finding the square of
insert data to text fi
what is the difference
system.out.println(x
iport
how to use maps in jav
jsp mysql combo box
struts e file jpeg
binary
ascending and descendi
server side validation
how to pass same varia
2 resultset
change color in JTabl
jstl basics tomcat
Jigloo
http get example
VNCj (Java VNC S
how to capture multipl
DOM
count
how to use unique cons
Eclipse 3.4 EJB
Interview question on
href
jfreechart tutorials
Photoshop Photo Effect
java random numbers
count row in resultset
jdbc using prepared st
Horizontal splitpane
link
logiceic:equal
Pattern Testing
Java Pass Value
html code for developi
modity data in text fi
Photoshop Text Effects
drop down in jsp
TextField
flex datagrids
sum of rows and coloum
display
multiple submit button
jsp bean
java example program t
populate drop down fro
vector in java
Struts Validator Frame
java xml
Get Array List in a JS
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.