繁体   English   中英

Javafx,css,为splitpane设置背景图片?

[英]Javafx, css, setting a background image for a splitpane?

我正在尝试将图片设置为拆分窗格的背景。 所以我的目标是,无论我如何通过拖动它们之间的分隔来调整两个锚定窗格的大小,我希望不要触及背景图片。

我尝试了几件事但没有成功。 我尝试将css添加到Scene Builder中的拆分窗格中:

.root {
 -fx-background-image: url("DSCF0806.JPG");
 }

这不会起作用......使用简单的图像视图它也不会工作,因为它使自己成为一个3.分裂区域,我不能把它放在两个分割区域之下。

直到现在我都找不到这种技术......你有什么想法吗? 谢谢!

.root指的是Scene的根。 在外部CSS文件中尝试以下操作:

.split-pane {
 -fx-background-image: url("DSCF0806.JPG");
 }

例如:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class SplitPaneWithBackground extends Application {

    @Override
    public void start(Stage primaryStage) {
        SplitPane splitPane = new SplitPane();
        splitPane.getItems().addAll(new StackPane(new Label("Left")), 
                new StackPane(new Label("Right")));


        BorderPane root = new BorderPane(splitPane);
        Scene scene = new Scene(root, 600, 400);
        scene.getStylesheets().add("split-pane-background.css");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

使用文件split-pane-background.css:

.split-pane {
    /*
    The image used below is copyright of Fedaro (Fernando da Rosa) y Santiago Roland
    (http://commons.wikimedia.org/wiki/User:Fedaro) and is used under the terms of the
    Creative Commons Attribution-Share Alike Unported 3.0 license. 
    (http://creativecommons.org/licenses/by-sa/3.0/deed.en).
    */
    -fx-background-image: url("http://upload.wikimedia.org/wikipedia/commons/a/a7/Nebulosa_de_Eta_Carinae_o_NGC_3372.jpg");
    -fx-background-size: cover ;
}
.label {
    -fx-background-color: rgba(255, 255, 255, 0.5) ;
    -fx-padding: 10 ;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM