Home Java Example Java Swing Adding Line to JTree



Adding Line to JTree
Posted on: May 30, 2007 at 12:00 AM
In this section, you will learn to create JTree along with a dividing Line. Here the tree gets divided into two parts separated by a line

Adding Line to JTree 

     

In this section, you will learn to create JTree along with a dividing Line. Here the tree gets  divided into two parts separated by a line. Both trees has the same root and the nodes. A JScrollPane provides a Scrollable property for viewing components to scroll. 

Program Description:

This program creates a box and two trees (tree1 and tree2). These trees contains the multiple nodes with  a root and scrollable property to scroll on the scroll bar to view nodes. The box divides frame into to two parts and sets the requirements. Here the first tree sets in the west side on the frame and another on the   east side. 

Here is the code of program:

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Container;

public class JTreeLineExample{

  public static void main(String args[]) {
  JFrame fm = new JFrame("JTree Line frame");
  fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  Container ca = fm.getContentPane();
  Box box = Box.createHorizontalBox();
  JTree tree1 = new JTree();
  JScrollPane scroll1 = new JScrollPane(tree1);
  JTree tree2 = new JTree();
  JScrollPane scroll2 = new JScrollPane(tree2);
  box.add(scroll1, BorderLayout.WEST);
  box.add(scroll2, BorderLayout.EAST);
  fm.getContentPane().add(box, BorderLayout.CENTER);
  fm.setSize(300250);
  fm.setVisible(true);
  }
}
 

Download this program.

Output this program:

 

Related Tags for Adding Line to JTree:
ctreeviewmultiplepropertyipviscrollthisainodeoocreaterootieboxwithprogramtoramcontainseitbardesmultinodesulpeinnomnttresprotreesstipeeatisllpropereaandarrtropetwscrssthababliplpleplpropprndodeonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Adding Line to JTree  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.