更改TitledPane的标题图像

时间:2017-07-26 07:31:12

标签: javafx javafx-8

使用监听器我打算改变TitledPane的背景图像,即使我没有实现它。当您启动代码时,样式表显示“DownArrow”,但是当您展开/折叠TitledPane时,图像将消失,并且不会显示任何内容。我使用的图像与代码和样式表位于同一文件夹中。我正在使用的代码如下:

        titledPane.expandedProperty().addListener((obs, wasExpanded, nowExpanded) -> {
            if (nowExpanded) {        
                titledPane.lookup(".title").setStyle(
                     "-fx-background-image : url('DownArrow.png'); " 
                );
            } else {
                titledPane.lookup(".title").setStyle(
                    "-fx-background-image : url('LeftArrow.png'); " 
                );                
            }
        });

CSS文件:

.titled-pane > .title {
    -fx-background-image : url('DownArrow.png'); 
    -fx-background-repeat: stretch;   
    -fx-background-position: right;
}

0 个答案:

没有答案
相关问题