Declaring Variable In JavaFX CSS File

前端 未结 5 1033
悲&欢浪女
悲&欢浪女 2020-12-08 20:10

I\'ve been inspecting the \"caspian.css\" distributed by Oracle in the JavaFX runtime library, and I see they have declared some color values as variables. Eg:



        
5条回答
  •  离开以前
    2020-12-08 20:45

    I know it is a quite old question but I couldn't find any answer with a similar approach as mine. As the previous answer already says it is not possible with standard css except for colors. (Please correct me if I am wrong)

    Nevertheless, it is possible if you are using less. I use less in one of my JavaFX projects and it works really well. You just have to configure your build process to compile your less files and generate the actual css files. I used maven in my project and below you can find my build configuration.

    
        
        
            
                src/main/resources
                
                    **/*.less
                
            
        
    
        
    
            
                maven-compiler-plugin
                3.3
                
                    1.8
                    1.8
                
            
    
            
                org.apache.maven.plugins
                maven-resources-plugin
                3.0.2
            
    
            
                com.zenjava
                javafx-maven-plugin
                8.7.0
                
                    com.example.project.Main
                
            
    
            
                maven-assembly-plugin
                
                    
                        
                            com.example.project.Main
                        
                    
                    
                        jar-with-dependencies
                    
                    false
                
            
    
            
            
                biz.gabrys.maven.plugins
                lesscss-maven-plugin
                1.2.1
                
                    
                        
                            compile
                        
                        
                            ${project.basedir}/src/main/resources/com/example/project
                            ${project.build.outputDirectory}/com/example/project
                        
                    
                
            
        
    
    

    With this configuration I'm now able to use less and there is no problem to define custom variables. I use a color-catalogue.less file in my project which all other less files can import via the import attribute. Maybe this solution helps anyone.


    Edit: If anyone is interested, a working example can be found here.

提交回复
热议问题