Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java Example Java Swing JTree Open Icon

Related Tutorials


Share on Google+Share on Google+

JTree Open Icon

In this section, you will learn to open an icon in JTree. That means when you click any node of a tree, icon will be displayed on the frame.

JTree Open Icon


In this section, you will learn to open an  icon in JTree. That means when you click any node of a tree, icon will be displayed on the frame. 

Program Description:

The following program displays icons when you click the node of JTree. For this you need an icon  to be displayed on the frame. Program uses the makeIcon() method to create a UIDefaults and an ImageIcon UIResource for the given specified gif file.The LookAndFeel plugins these component   Finally, the UIManager class keeps  the current look and feel of he given image to be showed, if you click any node of the tree. 

UIManager : 
The UIManager class keeps the current look and feel and its defaults which are as follows:.

  • If the system property swing.defaultlaf is non-null, the default look and feel is used .
  • If the exist and contains the swing.defaultlaf key, it uses its value as the default look and feels class uses its values..Otherwise it uses Java look and feel.

Here is the code of this program:

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

public class JTreeOpenIcon {
public static void main(String args[]) {
JFrame fm = new JFrame("JTree openIcon frame");
Object iconObject = 
(JTreeOpenIcon.class, "world.gif");
UIManager.put("Tree.leafIcon", iconObject);
JTree tree = new JTree();
JScrollPane scrollPane = new JScrollPane(tree);
Container contentPane = fm.getContentPane();
contentPane.add(scrollPane, BorderLayout.CENTER);

Download this program.

Output this program:


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 30, 2007

Related Tutorials

Discuss: JTree Open Icon   View All Comments

Post your Comment

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