© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
Quick Links
Easy Studies

JTree Open Icon Using Java


This program is to open an icon in JTree. That means when you click any node of a tree (e.g. Color, Sports, Food) icon will be displayed on the frame. This 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 sets an ImageIcon for the given specified gif file. The UIManager class keeps the current look and feel of the given image to be showed, if you click any node of the tree. 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 feel class uses its values. Otherwise it uses Java look and feel.

JTree Open Icon Using Java:

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, "package.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(300, 300); fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fm.setVisible(true); } }

Sample ScreenShot:

SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑