Java 鼠标左键时菜单颜色发生变化

Java 鼠标左键时菜单颜色发生变化,java,css,javafx,Java,Css,Javafx,我正在开发这个GUI,遇到了一个关于样式的小问题。我正在尽可能多地定制程序,但可能需要正确更改默认菜单样式。问题是,当我将鼠标悬停在菜单和菜单项上时,使用了正确的颜色。但是,当我离开按钮时,默认的蓝色会重新出现。您可以在“主题”按钮上看到这一点。如果我将鼠标悬停在它上面,它将变成当前照亮“Light”菜单项的红色 我尝试过其他psuedo选择器,如“.menu:按下、.menu:聚焦、.menu:选择”,但两个都没有成功。有什么建议吗?只需使用 。菜单栏{ -fx背景色:线性渐变(rgb(25

我正在开发这个GUI,遇到了一个关于样式的小问题。我正在尽可能多地定制程序,但可能需要正确更改默认菜单样式。问题是,当我将鼠标悬停在菜单和菜单项上时,使用了正确的颜色。但是,当我离开按钮时,默认的蓝色会重新出现。您可以在“主题”按钮上看到这一点。如果我将鼠标悬停在它上面,它将变成当前照亮“Light”菜单项的红色

我尝试过其他psuedo选择器,如“.menu:按下、.menu:聚焦、.menu:选择”,但两个都没有成功。有什么建议吗?

只需使用

。菜单栏{
-fx背景色:线性渐变(rgb(255、118、118)0%,rgb(237、101、101)100%);
-外汇选择栏:#ea5353;
-fx文本背景色:浅灰色;
-聚焦于fx的文本基色:白色;
}
这是一个测试线束:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MenuStyleTest extends Application {

    @Override
    public void start(Stage primaryStage) {

        Menu themes = new Menu("Themes", null, new MenuItem("Light"), new MenuItem("Dark"),
                new MenuItem("Cherry Blossom"));
        MenuBar menuBar = new MenuBar(new Menu("File"), themes, new Menu("Help"));

        BorderPane root = new BorderPane();
        root.setTop(menuBar);
        Scene scene = new Scene(root, 600, 600);
        scene.getStylesheets().add("style.css");

        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}
如果
style.css
包含上述css,则


我该如何了解该物业?它确实出现在这里:我怎样才能让文本填充保持不变?它不是一个属性;这是一种向上看的颜色。我通常只需转到默认样式表的第页就可以了解工作原理。通过一些文本填充实验进行更新。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MenuStyleTest extends Application {

    @Override
    public void start(Stage primaryStage) {

        Menu themes = new Menu("Themes", null, new MenuItem("Light"), new MenuItem("Dark"),
                new MenuItem("Cherry Blossom"));
        MenuBar menuBar = new MenuBar(new Menu("File"), themes, new Menu("Help"));

        BorderPane root = new BorderPane();
        root.setTop(menuBar);
        Scene scene = new Scene(root, 600, 600);
        scene.getStylesheets().add("style.css");

        primaryStage.setScene(scene);
        primaryStage.show();

    }

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