How can to change ui-icon's color in PrimeFaces?

前端 未结 1 1337
孤街浪徒
孤街浪徒 2021-02-08 10:47

I am developing a Web Java Application with JSF 2.2 and PrimeFaces 6.0. I am building a p:tree and I would like to change the ui-icons color as, for example, in the

1条回答
  •  滥情空心
    2021-02-08 10:55

    For me the most flexible and easiest solution is to use font-awesome 'icons' for the nodes. They are not effectively icons but as the name states, fonts. So these can be changed by css. Hence their popularity and why they are also included in PrimeFaces

    The PrimeFaces showcase for tree with icons shows that you can add custom icons for nodes, both the open and closed ones and also for the leaves. Luckily everything you add in the corresponding attributes client-side ends up in 'class' attributes on the html AND you can add multiple white space values in the attributes. This is what font-awesome needs, so by adding expandedIcon="fa fa-folder-open" or collapsedIcon="fa fa-folder" you can get the right icons and with a default style of .fa { color: orange} you get exactly what you want.

    In a full example with changed leaves would be something like this:

    
    
       
            
                
            
    
            
                
            
    
            
                
            
    
            
                
            
        
    
    

    But you can go a lot further. Look at the following image:

    It is produced with the following example:

    
    
        
            
                
            
    
            
                
            
    
            
                
            
    
            
                
            
        
    
    

    You can add additional 'classes' in the icon attributes, but you can also use the fa classes that are already added and use that in css selectors, or you can add specific conditional 'classes' in the icons based on values etc... And since it can all be changed by css, you can not only change the color, but also the size, rotation, css animations or whatever.

    0 讨论(0)
提交回复
热议问题