JTree cropping icons...
Hi, I have a set of 22x22pixel icons that I am displaying in a JTree. At this size however, the icons are having 2-4 pixels cropped off of them by the renderer. I have tried overriding the (s|g)etMinimumSize() methods of DefaultTreeCellRenderer, but to no avail. Does anyone have any advice, or a solution to this problem.
Many thanks.
Try
import javax.swing.plaf.basic.BasicTreeUI;
((BasicTreeUI)myTree.getUI()).setRightChildIndent(SOME_NUMBER);
((BasicTreeUI)myTree.getUI()).setLeftChildIndent(SOME_OTHER_NUMBER)
Similar Messages
-
The crop icon on the full edit tool bar.
The crop icon on the full edit tool bar is missing. It used to be there?
How can I add it back?No, it shares a slot with the recompose tool in PSE 9. Click hold on the icon that's below the type tool and you should see it:
-
I only seem to have 10 icons (features) available to use, for example the crop or straighten features are missing. Are these features restricted by some settings?
The faulting module is photoshop. Report below.
Source
Adobe Photoshop CC 2014
Summary
Stopped working
Date
2/2/2015 4:54 PM
Status
Report sent
Description
Faulting Application Path: C:\Program Files\Adobe\Adobe Photoshop CC 2014\Photoshop.exe
Problem signature
Problem Event Name: APPCRASH
Application Name: Photoshop.exe
Application Version: 15.2.2.310
Application Timestamp: 5480338c
Fault Module Name: Photoshop.exe
Fault Module Version: 15.2.2.310
Fault Module Timestamp: 5480338c
Exception Code: c000001d
Exception Offset: 00000000049de322
OS Version: 6.3.9600.2.0.0.768.101
Locale ID: 1033
Additional Information 1: 8db4
Additional Information 2: 8db473619c10c0c8b85ce99afe676ed8
Additional Information 3: f06d
Additional Information 4: f06da704bdd5338df2a8d09bde2244bb
Extra information about the problem
Bucket ID: 1fe6d1d4e5765bd348843b981b8ec4d2 (85990875000) -
Problem with JTree editing icons
Hello,
I want to edit another icons than the default icons in JTree object.
I look in the javadoc at the several methods, but I do not find a method witch can give me the possibility to setup the collapsed and expanded icon.
If some one now how to do that, it will be cool.
Thanks.I write this class :
public class SampleTreeCellRenderer extends TreeCellRenderer
/** Font used if the string to be displayed isn't a font. */
static protected Font defaultFont;
/** Icon to use when the item is collapsed. */
static protected ImageIcon collapsedIcon;
/** Icon to use when the item is expanded. */
static protected ImageIcon expandedIcon;
/** Color to use for the background when selected. */
static protected final Color SelectedBackgroundColor=Color.yellow;
static
try {
defaultFont = new Font("SansSerif", 0, 12);
} catch (Exception e) {}
try {
collapsedIcon = new ImageIcon("images/collapsed.gif");
expandedIcon = new ImageIcon("images/expanded.gif");
} catch (Exception e) {
System.out.println("Couldn't load images: " + e);
public SampleTreeCellRenderer() {
super();
public SampleTreeCellRenderer(String collapsedImagePath,String expandedImagePath) {
super();
try {
if (collapsedImagePath!=null) collapsedIcon = new ImageIcon(collapsedImagePath);
if (expandedImagePath!=null) expandedIcon = new ImageIcon(expandedImagePath);
} catch (Exception e) { System.out.println("Couldn't load images: " + e); }
public void setCollapsedIcon(String path) {
try {
if (path!=null) collapsedIcon=new ImageIcon(path);
} catch (Exception e) { System.out.println("Couldn't load images: " + e); }
public void setExpandedIcon(String path) {
try {
if (path!=null) expandedIcon=new ImageIcon(path);
} catch (Exception e) { System.out.println("Couldn't load images: " + e); }
/** Whether or not the item that was last configured is selected. */
protected boolean selected;
public Component getTreeCellRendererComponent(
JTree tree, Object value,
boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
Font font;
String stringValue = tree.convertValueToText(value, selected,expanded,leaf,row,hasFocus);
/* Set the text. */
setText(stringValue);
/* Tooltips used by the tree. */
setToolTipText(stringValue);
/* Set the image. */
if(expanded) { setIcon(expandedIcon); }
else if(!leaf) { setIcon(collapsedIcon);}
else { setIcon(null);}
/* Update the selected flag for the next paint. */
this.selected = selected;
return this;
public void paint(Graphics g) {
super.paint(g);
} // end of class SampleTreeCellRenderer
I test it but I do not understand why it do not display the icons. -
JTree changing Icons of leaves of a node
I have a Jtree with root node as "Project"
I have nodes as "color", "sports", "food" which in turn have leaves.
I have to set an Icon "Icon1" for all the leaves of node "color"
I have to set another Icon "Icon2" for all leaves of node "sports"
and have to set another Icon3" for all the leaves of node "food"
How do I go about doing it? Thanks.Take a look at the Swing Tutorial, specifically http://web2.java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display. This gives a straightforward example of changing icons (or anything on the node) by using a cell renderer.
-
Hi, i am trying to get custom icon for specific nodes of a tree. In my customTreeCellrenderer that extends the default predecessor, i have this function. The problem is that, the icons are not set to the node i want but the node after that node. Anyone got any suggestions as to what i am doing wrong ?
Thanks, Dave
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
ImageIcon error = new ImageIcon("illegal.gif");
super.getTreeCellRendererComponent(tree, value, sel,expanded, leaf, row,hasFocus);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
GroupNodeObject obj = (GroupNodeObject) node.getUserObject();
if(node.getUserObject() instanceof GroupNodeObject){
if(obj.isIllegal()){
this.setLeafIcon(error);
this.setClosedIcon(error);
this.setOpenIcon(error);
}else{
this.setLeafIcon(getDefaultLeafIcon());
this.setClosedIcon(getDefaultClosedIcon());
this.setOpenIcon(getDefaultOpenIcon());
return this;
}may be the next node is instance of GroupNode!!
just incase, check the code if the error is assigning the nodes!
This code looks ok. -
Ok i know how to set a icon for all nodes in a JTree but my problem is setting incons for certain nodes. I am trying to Create a UML Training Tool for my degree and i have major trouble here. I can change the icons for all but all i want to do is change them for individual nodes, for example a different icon for an actor to a use case, please please can someone help this beginner.
You need to subclass DefaultTreeCellRenderer and override the getTreeCellRendererComponent method, like:
class CustomRenderer extends DefaultTreeCellRenderer {
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel,expanded, leaf, row, hasFocus);
if (whatever) setIcon(myIcon);
} Then set the cell renderer for your tree:
myTree.setCellRenderer(new CustomRenderer()); -
JTree - Parent Icon for children
Hello,
I have a JTree that displays Categories (=Parent) and it's content (=Child):
Cat 1
Cat 2
Content 1
Cat 3
Cat 3.1
Content
...There are some categories that do not have children, and so their icon is the same as the leaves's icon.
How can I change the icon of categories who do not have children to a "parent-icon"?
thanks,Inherit DefaultTreeCellrenderer and override getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus). Now you can set the icons individually.
Tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html -
I have created a JTree that works fine. I wonder If there is a way of changing the tree icon of a specific leaf when I selected (Only that particular leaf). I tried few things with TreeRenderer but the best done was that I managed to change all the leaf.
Thank you for your help.Use a TreeCellRenderer instead. It has a parameter that tells you whether the cell is selected, so you can assign a different icon based on that parameter.
-
I would like to set the leaves icon of a JTree.
I used a DefaultTreeCellRenderer and the method setLeafIcon.
What i want to do is set two different icons for two different kind of leaf ....
is it possible ?????
Thanks.Yes, that's possible.
I would recommend the following:
a) derive you renderer from DefaultTreeCellRenderer (you probably know this already);
b) in its main method getTreeCellRendererComponent() call the super implementation (super.getTreeCellRendererComponent());
c) use given parameters to determine the kind of tree node the renderer is going to 'paint' on the screen (parameters 'value', 'leaf');
d) access your data structures (or whatever you plan to have) to find out the kind of Icon you want to set for that tree node;
e) call method setIcon() of your renderer class. As it is derived from JLabel, it shall understand this call correctly.
You are done. -
Hello,
Introduction:
The hierarchical model is a part of the reality, a lot of real examples could be implemented, however the difficulty is to make the nodes of the Jtree closer as possible to the real model.
My needs:
1\I need a JTree which should executed as applet.
2\the top , the branches, and the leaves should customizable.(I would like to have a special icons for each)
3\when clicking the user should have a data from a java servlet throught tomcat according to each node.
4\Internationnalization.
The actual situation:
1\I have the tree which executes as applet,
2\I can customize the leaf only by asigning an icon, according to displayed text for the leafe!!!!!!!!!:(
what about the top of the tree and the branches?
also, that will be a reall problem when I will try to make an internationnalization!, isn't it?
so I need a way to make a difference for displayed text and something like an identificator for the tree.
3\When clicking a tree node the action is to launch an url for a servlet whith passing the displayed text in the tree as a parameter, then the servlet will display the corresponding document(jsp).
as it's explained in 2\ that will be a real problem when internationnalizing.
My Questions:
1\Is there any way the customize all the icons in a tree?, one by one...
2\Is it possible to refer to a node with an identificator?, as an internal identificator for the programme.And of course the displayed text will different?
3\Please, provide my with some working codes sources.
Thanks and Regards,
kifwetHi,
I was working on tree icons last week. I used a tree renderer.
Something like that :
JTree tree;
tree.setCellRenderer(new MyRenderer());
private class MyRenderer extends DefaultTreeCellRenderer {
Icon treeCollapsedIcon;
Icon treeExpandedIcon;
Icon leafIcon;
public MyRenderer() {
super();
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (leaf ) {
setIcon(leafIcon);
} else {
if (expanded) {
setIcon(treeExpandedIcon);
}else{
setIcon(treeCollapsedIcon);
return this;
I hope this will help you
Zauz -
Hi,
I am doing a sort of explorer, with a JTree.
I know how to change icons for leafs, but sometimes my leafs are indeed branches but without nothing in it (an empty directory).
so the tree displays it as a leaf. But I would like that the tree displays it with the directory icon (but without the "+" sign).
How can i do this ?
Sylvain.I haven't such problems...
Ok. You have to create your custom TreeCellRenderer and set it to the tree.
IconRenderer myRenderer=new IconRenderer ();
tree.setCellRenderer(myRenderer);
class IconRenderer extends JLabel implements TreeCellRenderer
public Component getTreeCellRendererComponent(JTree tree,
Object value, boolean sel, boolean expanded, boolean leaf,
int row, boolean hasFocus)
setText(value.toString());
//process value (value represents you tree node content)
if (!leaf) {
if (expanded)
setIcon(new ImageIcon("images/expanded.gif"));
else
setIcon(new ImageIcon("images/collapsed.gif"));
else {
setIcon(new ImageIcon("images/text.gif"));
MyObject myObj=(MyObject)value;
if (myObj.isBranch()) {
setIcon(new ImageIcon("images/branch.gif"));
regards
Stas -
JTree control icons. How do I get rid of those suckers?
Okay, so I'm using a JTree cldonkey (you can't say class, so please replace every occurence of cldonkey with the correct word, and please use it instead of class, I think it's funny, even though you don't), and I HATE those stupid little circles. How can I replace them with my own icon? I've found the MetalIconFactory. Do I do it in there? I wish I knew, then I would die happy, in a few decades.
Try using the UIManager to change the default icons:
UIManager.put( "Tree.openIcon", yourOpenIcon );
UIManager.put( "Tree.closedIcon", yourClosedIcon );For a list of all properties of the JTree component as well as all other components, check out this program:
http://www.discoverteenergy.com/files/ShowUIDefaults.java -
How can I change the icon in the JTree of JavaHelps TOC when I expand or close the node. I understand that I need to give the tree a different cell renderer but can't find out where to do that. Does anyone have an example of this?
Thanks,
Rich
DeveloperThankyou for your help. I am getting a lot closer. There is something I am still missing though. I am sure I am setting the cell renderer to the tree now. The problem is that it is not effecting the images at all. Here is my code for this. Can you see what I am doing wrong?
private void jButtonHelp_ActionPerformed()
try
ClassLoader loader = this.getClass().getClassLoader();
URL helpURL = HelpSet.findHelpSet(loader, "helpset.hs");
m_hs = new HelpSet(loader, helpURL);
HelpBroker hb = m_hs.createHelpBroker();
JHelp jhelp = new JHelp(m_hs);
JHelpTOCNavigator jhtoc = null;
hb.setDisplayed(true);
new CSH.DisplayHelpFromSource(hb);
for(Enumeration enum = jhelp.getHelpNavigators();enum.hasMoreElements();)
try
jhtoc = (JHelpTOCNavigator)enum.nextElement();
break;
catch(Exception ee){}
if(jhtoc != null)
JTree aTree = getNavTree(jhtoc);
aTree.setCellRenderer(new HelpTreeRenderer());
aTree.updateUI();
jhelp.updateUI();
catch (Exception e)
System.out.println("Help Exception " + e.getMessage());
class HelpTreeRenderer extends DefaultTreeCellRenderer{
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
try
DefaultTreeCellRenderer treeCellRender = (DefaultTreeCellRenderer)
super.getTreeCellRendererComponent(tree, value, selected, expanded,
leaf, row, hasFocus);
DefaultMutableTreeNode node =(DefaultMutableTreeNode)value;
if(node.getLevel() == 1) treeCellRender.setIcon(getImageDepartment());
catch (Exception e)
System.out.println("HelpTreeRenderer Inner Class WIP Viewer Exception " + e.getMessage());
return this;
} -
JTree node icon adnd leaf icons
Need Help.......
Need to change icon in the root node and leaf ; but they must be different each other . Trying to use a renderer but change every leaf with same icon .same happend to nodes.
Thanks a lothave you gone through this
[tree display|http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display]
and also try searching the forum there are lot more similar post.
Maybe you are looking for
-
Hi, People at our company installed the latest Java for OSX 2013-004 1.0 Apple Update and all of our software installers failed to run anymore. The only way to kill the installer was Apple Menu -> Force Quit after that. We all had to downgrade to Jav
-
Script not executing the CALCDEFAULT
I've got a load script which gets run everynight, using ESSCMD, which loads new data into an essbase cube, this all seems to work OK, but it doesnt recalculate the cube data. If I run the calcdefault from within the EAC all is OK. Can someone advise
-
I signed up with adobe cc & lr bundle. I downloaded CC but i can not find the app anywhere on my iMac. its really frustrating!
-
EJB calling EJB - Very very slow in iAS
We have an EJB deployed to the iCache instance of iAS that calls another EJB on the same instance. We experience serious performance problems when executing this call. The response time is up to 3 Minutes !!! Are there any configurations that I have
-
Can a Wireless Keyboard and Mouse Wake my MB?
Hello Everyone, I just purchased an external monitor, which I am planning on wall-mounting. While at my desk, I will have my MacBook in a drawer with the Apple Wireless Keyboard and Mouse on the desk, in order to create more space. Which brings me to