gpt4 book ai didi

菜单栏中的 JavaFX ChoiceBox

转载 作者:行者123 更新时间:2023-12-01 09:37:03 25 4
gpt4 key购买 nike

我使用 JavaFX 制作了一个应用程序。

我想在我的顶部 MenuBar 中有一个 ChoiceBox 来选择语言。我想在选择语言控件时禁用蓝色周围。我该怎么做?

image[1]

最佳答案

将包含 ChoiceBoxMenuId 设置为 透明 并使用以下 CSS:

#transparent:hover,
#transparent:focused,
#transparent:showing {
-fx-background: transparent;
}

不幸的是,我还不知道如何使用 transparent 作为一个类来做到这一点。

<小时/>

示例

输出: enter image description here

代码:

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

public class Foo extends Application {

@Override
public void start(Stage stage) throws Exception {
Menu fileMenu = new Menu("File");

ChoiceBox<String> languageBox = new ChoiceBox<String>();
languageBox.getItems().addAll("English", "Deutsch");

Menu languageMenu = new Menu();
languageMenu.setId("transparent");
languageMenu.setGraphic(languageBox);

MenuBar menuBar = new MenuBar();
menuBar.getMenus().addAll(fileMenu, languageMenu);

BorderPane root = new BorderPane();
root.setTop(menuBar);

Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

stage.setScene(scene);
stage.setTitle("MCVE");
stage.setWidth(640);
stage.setHeight(480);
stage.show();
}

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

}

关于菜单栏中的 JavaFX ChoiceBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38817465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com