在我的应用程序中,我使用 aMenuButton
来提供操作的下拉列表。a 上的默认下拉指示器MenuButton
是一个向下的黑色三角形。我想将其更改为指向下方的白色三角形以匹配我的文本颜色。
以防我不清楚,这是一个应该清除它的屏幕截图。
我尝试在 fxml 文件中放置一个图形,如下所示:
<MenuButton contentDisplay="RIGHT" graphicTextGap="10.0" layoutX="92.0" layoutY="73.0" mnemonicParsing="false" styleClass="toolbar-button" text="MenuButton">
<graphic>
<ImageView fitHeight="4.0" fitWidth="7.0" mouseTransparent="true" preserveRatio="true">
<image>
<Image url="@Arrow_Down.png" preserveRatio="true" smooth="false" />
</image>
</ImageView>
</graphic>
<items>
<MenuItem mnemonicParsing="false" text="Action 1" />
<MenuItem mnemonicParsing="false" text="Action 2" />
</items>
</MenuButton>
但这给了我一个黑白三角形:
如果我能以某种方式隐藏可以工作的黑色三角形,但似乎应该有一种方法可以将菜单按钮设置为白色而不是白色。
这里是 Sample.fxml 给那些想要帮助的人:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200.0" prefWidth="320.0" xmlns:fx="http://javafx.com/fxml">
<children>
<MenuButton contentDisplay="RIGHT" graphicTextGap="10.0" layoutX="92.0" layoutY="73.0" mnemonicParsing="false" styleClass="toolbar-button" text="MenuButton">
<graphic>
<ImageView fitHeight="4.0" fitWidth="7.0" mouseTransparent="true" preserveRatio="true">
<image>
<Image url="@Arrow_Down.png" preserveRatio="true" smooth="false" />
</image>
</ImageView>
</graphic>
<items>
<MenuItem mnemonicParsing="false" text="Action 1" />
<MenuItem mnemonicParsing="false" text="Action 2" />
</items>
</MenuButton>
</children>
<stylesheets>
<URL value="@test.css" />
</stylesheets>
</AnchorPane>
test.css:
root {
display: block;
}
.toolbar-button {
-fx-background-color: #006699;
-fx-padding: 2 4 4 4;
-fx-text-base-color: #FFFFFF;
-fx-font-weight: bold;
-fx-font-size: 12px;
}
.toolbar-button:hover {
-fx-background-color: #B2E1FF;
-fx-padding: 2 4 4 4;
-fx-text-base-color: #000000;
-fx-font-weight: bold;
-fx-font-size: 12px;
}
以及运行它的 Test.java:
package test;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Test extends Application {
public static void main(String[] args) {
Application.launch(Test.class, args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
stage.setScene(new Scene(root));
stage.show();
}
}
那么如何让黑色三角形变成白色三角形呢?