Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Adding Horizontal lines to Group Nodes

In this section, you will learn to create a horizontal tree in java.

Adding Horizontal lines to Group Nodes

                         

Introduction

In this section, you will learn  to create a horizontal tree in java.

Description of the Program:

This program creates a JTree that contains a root and the nodes.This program implements a class (JTreeHorizontal). Here the init() method creates  root and the child nodes through DefaultMutableTreeNode method. These objects are added in the JTree and the putClintProperty() method displays them horizontally in a  JTree on the frame. 

putclientProperty(Object key, Object val):  The clientProperty dictionary is not intended to support large scale extensions to Jcomponent nor should it  be considered an alternative to subclassing when designing a new component. It takes following type values:

        key: This is the client property key.
        val: This is the client property value.

Here is the code of this program:

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

public class JTreeHorizontal extends JFrame{
  JTree tree;
  public JTreeHorizontal(){
    super("JTreeHorizontal Frame");
    setSize(300300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }

  public void init(){
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode book = new DefaultMutableTreeNode("Book");
    DefaultMutableTreeNode javabook = new DefaultMutableTreeNode("Java Book")
    DefaultMutableTreeNode jspbook = new DefaultMutableTreeNode("JSP Book")
    DefaultMutableTreeNode phpbook = new DefaultMutableTreeNode("PHP Book")
    DefaultMutableTreeNode structbook = new DefaultMutableTreeNode("STRUCT Book")
    DefaultMutableTreeNode contry = new DefaultMutableTreeNode("CONTRY");
    DefaultMutableTreeNode india = new DefaultMutableTreeNode("INDIA");
    DefaultMutableTreeNode usa = new DefaultMutableTreeNode("USA");
    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);
    tree.putClientProperty("JTree.lineStyle""Horizontal");
    treeModel.insertNodeInto(book,root, 0);
    treeModel.insertNodeInto(contry,root, 0);
    book.add(javabook);
    book.add(jspbook);
    book.add(phpbook);
    book.add(structbook);
    contry.add(india);
    contry.add(usa);
    getContentPane().add(tree, BorderLayout.CENTER);
  }

  public static void main(String args[]){

    JTreeHorizontal jh = new JTreeHorizontal();
    jh.init();
    jh.setVisible(true);
  }
}

Download this program.

Output this program: 

                         

» View all related tutorials
Related Tags: c com class orm ant form model io components sed color format component value byte int rgb show pixel for

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 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

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

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

Copyright © 2008. All rights reserved.