Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Disable TreeNode icon if needed

    Hi,

    I would like to know how is it possible to disable the TreeNode icons one by one. Some nodes needs to have an icon, while others not.

    I can only call TreeNode.setIcon() to a node, which replaces the folder or node icon. However I am unable to call for example a TreeNode.hideIcon(), which would hide the icon for that node and also remove the gap created for the icon.

    Another issue I have, which is connected to this, is that it is impossible to disable the folder icon, or the node icon. I managed to do that only by setting the TreeGrid.setIconSize(1) and by using a small 1px x 1px transparent image for example. But this will set the icon size to 1 in the whole tree, while I would like to disable just the folder icons.

    I am using the latest smartgwt 4.0. I just updated to it, previously I was using 3.1, and there were no problems with this. In that case I was setting the folderIcon and nodeIcon to null, which removed the default folder and node icons. Then I called a TreeNode.setIcon() for those cases, when I needed an icon, and that was working fine. Currently, without modifying my code, there are gaps for the icons, where I didn't set any icon. So I started to test the tree in an empty project, with the default skin and without any customization, but I noticed I am unable to do the same with 4.0.

    Is there any workaround or solution exists?

    Thanks!

    #2
    I figured it out, thanks to the devconsole.

    Here is my solution:
    The TreeNode doesn't have an interface for it, but if the setAttribute("iconSize", 1); is called, then we can set the icon size to 1, just to that node. So I set the folderIcon and nodeIcon to null to the whole tree, then I initialize every single node with this attribute (it is needed, because by default if this attribute is not set, then the tree's iconSize is used). I override the TreeNode's setIcon and after calling the super.setIcon(), I call the setAttribute("iconSize", iconSize), where iconSize is the integer icon size from the tree. This way it works.

    Hope it helps someone. However it would be nice to have some official way to do this.

    Comment


      #3
      Thank you!!!

      Originally posted by mikereem View Post
      I figured it out, thanks to the devconsole.

      Here is my solution:
      The TreeNode doesn't have an interface for it, but if the setAttribute("iconSize", 1); is called, then we can set the icon size to 1, just to that node. So I set the folderIcon and nodeIcon to null to the whole tree, then I initialize every single node with this attribute (it is needed, because by default if this attribute is not set, then the tree's iconSize is used). I override the TreeNode's setIcon and after calling the super.setIcon(), I call the setAttribute("iconSize", iconSize), where iconSize is the integer icon size from the tree. This way it works.

      Hope it helps someone. However it would be nice to have some official way to do this.
      This was something that I ran into last week. Ended up throwing up my hands when I either got rid of the icons alltogether or was forced to have the extra space for the folder nodes.

      Thank you so much for posting the solution. It works for me as well.

      One questions, any idea why "iconSize" = 0 doesn't work but 1 does?

      Comment


        #4
        Originally posted by jornn View Post
        This was something that I ran into last week. Ended up throwing up my hands when I either got rid of the icons alltogether or was forced to have the extra space for the folder nodes.

        Thank you so much for posting the solution. It works for me as well.

        One questions, any idea why "iconSize" = 0 doesn't work but 1 does?
        I'm glad it helped you! I didn't tried with iconSize 0, perhaps it would work. The folderIcon and nodeIcon is set to null, so there is nothing to show on that 1px. It could be only a problem if you need to be pixel perfect.

        Comment

        Working...
        X