简体   繁体   English

如何在JavaFX中设置FXTable的TableMenuButton上下文菜单的背景和文本颜色的样式?

[英]How to style the Background and the text color of the TableMenuButton context menu of a FXTable in JavaFX?

When we enable the TableMenuButton on a FXTable we will get a context menu that enable to show and hide colomuns. 当我们在FXTable上启用TableMenuButton时,我们将获得一个上下文菜单,该菜单可以显示和隐藏colomuns。

knowing that my table do have a specific styling I want to restyle this context menu background color and text color. 知道我的桌子确实有特定的样式后,我想重新设置此上下文菜单的背景颜色和文本颜色。

I don't know how! 我不知道!

You must add a CSS stylesheet which modifes TableView's ContextMenu. 您必须添加一个CSS样式表来修改TableView的ContextMenu。 Depending on which table view you are using, delete 'tree' or w/o 'tree' lines: 根据您使用的表视图,删除“ tree”行或不包含“ tree”行:

.table-view .column-header .context-menu,
.tree-table-view .column-header .context-menu,
.table-view > .column-header-background > .show-hide-columns-button .context-menu,
.tree-table-view > .column-header-background > .show-hide-columns-button .context-menu {
    -fx-background-color: black;
}

If you want to change menu item's background color: 如果要更改菜单项的背景色:

.table-view .column-header .context-menu .menu-item,
.tree-table-view .column-header .context-menu .menu-item,
.table-view > .column-header-background > .show-hide-columns-button .context-menu .menu-item,
.tree-table-view > .column-header-background > .show-hide-columns-button .context-menu .menu-item {
    -fx-background-color: green;
}

If you want to change menu item label's color: 如果要更改菜单项标签的颜色:

.table-view .column-header .context-menu .menu-item > .label,
.tree-table-view .column-header .context-menu .menu-item > .label,
.table-view > .column-header-background > .show-hide-columns-button .context-menu .menu-item > .label,
.tree-table-view > .column-header-background > .show-hide-columns-button .context-menu .menu-item > .label {
    -fx-text-fill: yellow;
}

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

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