簡體   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