[英](JavaFX FXML) While trying to make a custom button, how do I get an image to completely fill a button?
(JavaFX FXML) 我目前正在使用場景構建器來制作一個應用程序,我正在嘗試制作一個自定義按鈕,我設法將圖像放到按鈕上,但我不知道如何讓圖像完全填充按鈕。 有任何想法嗎? 哦,如果有另一種創建自定義按鈕的方法也會有所幫助!
這是我的 FXML 代碼:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button layoutX="165.0" layoutY="125.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="270.0">
<graphic>
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@case.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
圖像適合按鈕,但我希望它完全填充按鈕,或者如果有任何不同的方式將不勝感激!!!
先感謝您!
PS:我正在使用 Scene Builder,該應用程序的任何有用提示也將非常有幫助
如果我理解正確,您根本不想看到按鈕邊框和顏色。 您可以通過這樣的 CSS 自定義您的按鈕:
.fill-btn {
-fx-graphic: url("@case.png");
-fx-background-color: inherit;
-fx-opacity: inherit;
-fx-border: none;
}
並在您的 fxml 中聲明它:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button stylesheets="@buttons-style.css" styleClass="fill-btn" layoutX="165.0" layoutY="125.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="270.0">
</Button>
</children>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.