Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在Tornado fx上将背景图像添加到根目录_Css_Kotlin_Tornadofx - Fatal编程技术网

Css 如何在Tornado fx上将背景图像添加到根目录

Css 如何在Tornado fx上将背景图像添加到根目录,css,kotlin,tornadofx,Css,Kotlin,Tornadofx,我正在学习kotlin+TornadoFXcombo 实际上,我在设计UI时遇到了一个问题,我的目标是在我的windows上设置一个背景图像 class StyleSheet : Stylesheet() { init { root { backgroundImage += URI("/background.jpg")//Uri recognized but img is not loaded // background

我正在学习
kotlin+TornadoFX
combo

实际上,我在设计UI时遇到了一个问题,我的目标是在我的windows上设置一个
背景图像

class StyleSheet : Stylesheet() {

    init {

        root {
             backgroundImage += URI("/background.jpg")//Uri recognized but img is not loaded
    //        backgroundColor +=Color.BLANCHEDALMOND //this still work
        }

        textArea {
            content {
                backgroundColor += Color.LIGHTGREY
            }
        }
        listView {
            backgroundColor += Color.TRANSPARENT
        }
    }


}
我已经从IDE
background.jpg
位置进行了检查 (来自intellij存储库的复制路径)background.jpg
我已经有一个资源文件夹(jvmMain/kotlin/resources),并且编辑器识别bg uri是正确的(例如,如果我将jpg移动到另一个文件夹中,intellij将更新uri),我在loadin上没有任何错误/警告分段,但我还有经典的灰色bg


我刚刚测试了它,它似乎有效。但这似乎是一个挑剔的过程。最重要的是,您的图像需要设置到资源文件夹中。我没有别的办法让它工作。如果您的图像直接位于您的资源文件夹中,那么
URI(“/background.jpg”)
应该可以工作。如果它在resources文件夹的子目录中,比如说“images”,那么
URI(“/images/background.jpg”)
应该可以使用

风格{
backgroundImage+=文件(“src/jvmMain/resources/background.jpg”).toURI()
}

我已经有了一个资源文件夹(jvmMain/kotlin/resources),并且编辑器识别出bg uri是正确的(例如,如果我将jpg移动到另一个文件夹中,intellij将更新uri),我在loadin上没有任何错误/警告分段,但我还有经典的灰色bg。