简体   繁体   English

如何使用JavaFX消除(或着色)子菜单的页边距?

[英]How can I get rid (or color) the margins of a submenu using JavaFX?

Can anyone give an advice on what to do to get rid of the white margins of a submenu (or at least how can I change margin's color)? 任何人都可以就如何去除子菜单的白色边距提出建议(或者至少如何更改边距的颜色)? I tried: 我试过了:

  • "-fx-indent: 0px;" “ -fx-indent:0px;”
  • "-fx-start-margin: 0px;" “ -fx-start-margin:0px;”
  • "-fx-end-margin: 0px;" “ -fx-end-margin:0px;”
  • "-fx-padding: 0px;" “ -fx-padding:0px;”

but nothing seems to work 但似乎没有任何作用

The class looks like this: 该类如下所示:

public static void assembleMenuPane(VBox masterPane) {
    ArrayList<String> list = new ArrayList<String>() {{
        add("A");
        add("B");
        add("C");
    }};

    Menu menuOptions = new Menu("Options");
    menuOptions.setStyle("-fx-font-size:12; -fx-background-color: #c9c9c9;");

    Menu menuOptionsChild = new Menu("Opt_1");
    menuOptionsChild.setStyle("-fx-border-color: yellow;" +
            " -fx-background-color: red;" +
            " -fx-indent: 0px;" +
            " -fx-start-margin: 0px;" +
            " -fx-end-margin: 0px;" +
            " -fx-padding: 0px;");

    menuOptions.getItems().add(menuOptionsChild);
    list.forEach((children) -> menuOptionsChild.getItems().add(new MenuItem(children)));

    MenuBar menuBar = new MenuBar();
    menuBar.setStyle("-fx-background-color: #bf6dbf;");
    menuBar.getMenus().addAll(menuOptions);
    VBox menuBarPane = new VBox(menuBar);
    masterPane.getChildren().add(menuBarPane);
}

and the output is as follows: 输出如下:

苏姆贝努

Here is a link to the root CSS file used with scene builder: modena.css 这是与场景构建器一起使用的根CSS文件的链接: modena.css

Take a look at the menu, menu bar, and menu item section. 查看菜单,菜单栏和菜单项部分。 If I understand what you want the following two styles will remove the white space in the context menu. 如果我了解您想要的内容,以下两种样式将删除上下文菜单中的空白。

.context-menu { 
-fx-padding: 0; }

.menu-item {
-fx-padding: 0; }

There is also a left and right container in that particular menu item. 该特定菜单项中还有一个左右容器。 The left container has the text displayed and the right container has the arrow in it. 左侧的容器中显示了文本,右侧的容器中显示了箭头。 To get the effect you want, you need to make sure you are applying it to the correct node in the modena.css file. 为了获得所需的效果,您需要确保将其应用于modena.css文件中的正确节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM