Icon Change in Leafnode of Jtree


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Icon Change in Leafnode of Jtree

  1. #1
    Saibal Guest

    Icon Change in Leafnode of Jtree



    How do I change the icon of the leafnode when clicking
    on JTree Swing Component?



  2. #2
    Paul Clapham Guest

    Re: Icon Change in Leafnode of Jtree

    If you want to control how a tree node is displayed in a JTree, you need to
    use a TreeCellRenderer class.

    PC2

    Saibal <sanmitsai@yahoo.com> wrote in message
    news:3a1b9591$1@news.devx.com...
    >
    >
    > How do I change the icon of the leafnode when clicking
    > on JTree Swing Component?
    >
    >




  3. #3
    saibal sanmitsai Guest

    Re: Icon Change in Leafnode of Jtree


    The TreeCellRenderer class changes all the leaf-node icons
    I only need to change a paticular leaf node icon when it will
    be clicked.

    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >If you want to control how a tree node is displayed in a JTree, you need

    to
    >use a TreeCellRenderer class.
    >
    >PC2
    >
    >Saibal <sanmitsai@yahoo.com> wrote in message
    >news:3a1b9591$1@news.devx.com...
    >>
    >>
    >> How do I change the icon of the leafnode when clicking
    >> on JTree Swing Component?
    >>
    >>

    >
    >



  4. #4
    Paul Clapham Guest

    Re: Icon Change in Leafnode of Jtree


    <saibal sanmitsai> wrote in message news:3a1cfd99$1@news.devx.com...
    >
    > The TreeCellRenderer class changes all the leaf-node icons
    > I only need to change a paticular leaf node icon when it will
    > be clicked.
    >

    What do you mean by "when it will be clicked"? Do you want a different icon
    to flash as you click, then the original icon to reappear when you lift your
    finger from the mouse? Or do you want the different icon to appear on
    selected nodes? The TreeCellRenderer can show a different icon for selected
    nodes.




  5. #5
    saibal Guest

    Re: Icon Change in Leafnode of Jtree


    Yes I want the icon to changed when selected.
    I am able to cahnge the icon for the nodes but
    not the leaf-nodes(the nodes that do not have child).




    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >
    ><saibal sanmitsai> wrote in message news:3a1cfd99$1@news.devx.com...
    >>
    >> The TreeCellRenderer class changes all the leaf-node icons
    >> I only need to change a paticular leaf node icon when it will
    >> be clicked.
    >>

    >What do you mean by "when it will be clicked"? Do you want a different

    icon
    >to flash as you click, then the original icon to reappear when you lift

    your
    >finger from the mouse? Or do you want the different icon to appear on
    >selected nodes? The TreeCellRenderer can show a different icon for selected
    >nodes.
    >
    >
    >



  6. #6
    Paul Clapham Guest

    Re: Icon Change in Leafnode of Jtree


    saibal <sanmitsai@yahoo.com> wrote in message
    news:3a208753$1@news.devx.com...
    >
    > Yes I want the icon to changed when selected.
    > I am able to cahnge the icon for the nodes but
    > not the leaf-nodes(the nodes that do not have child).
    >

    If you use a TreeCellRenderer, you have to implement a method that looks
    like this:

    getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
    boolean expanded, boolean leaf, int row, boolean hasFocus)

    Notice that it has a boolean parameter that tells you whether the node you
    are rendering is selected or not. Use this parameter to decide what icon
    you are going to display.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center