Home Java Example Java Swing JTree Open Icon



JTree Open Icon
Posted on: May 30, 2007 at 12:00 AM
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 swing.properties 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 = 
LookAndFeel.makeIcon
(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);
fm.setSize(300300);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setVisible(true);
  }
}

Download this program.

Output this program:

Related Tags for JTree Open Icon:
cimagefileideuitreemakeiconsmethoddisplayicondefaultviclicksourceresourceclithisidnodecreategifframeifforieexampleprogramtoramjtreeexameachcieillispluseulpeimcefaultinnomplaytrjispclesspecagercicomeproxawhenxampsspsoeefaultsatkisirhaltsivmpleaandconsuidusesssteateachthhatdispefaultframmageidefidefpleplprndodeonogro


More Tutorials from this section

Ask Questions?    Discuss: JTree Open Icon   View All Comments

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.