【问题标题】:Style ChoiceBox list with CSS in JavaFXJavaFX 中带有 CSS 的样式选择框列表
【发布时间】:2017-09-17 17:11:56
【问题描述】:

如何在 CSS 或代码中访问此列表以设置样式。我无法从 modena.css 中弄清楚。

通过使用

.choice-box > * {
    -fx-background-color: black;
}

列表不受影响,因此它是某种单独的控件。

【问题讨论】:

  • 欢迎来到 StackOverflow!为了让我们帮助您处理 CSS,您还需要向我们展示您的相关 HTML;没有它,我们无法回答您的问题。请更新您的问题,使其在minimal, complete, and verifiable example 中显示所有相关代码。如果您的 HTML 已生成,请将 HTML 发布到您的后端输出。如需更多信息,请参阅有关how to ask good questions 的帮助文章,并采取tour of the site :)
  • 我的意思是 this 一种 css。对不起,如果我不应该使用 css 标签。没有 HTML。

标签: java css javafx


【解决方案1】:

以下选择器应在ChoiceBox 的上下文菜单中进行着色:

// Background color of the whole context menu
.choice-box .context-menu { -fx-background-color: black; }
// Focused item background color in the list
.choice-box .menu-item:focused { -fx-background-color: orange; }
// Text color of non-focused items in the list
.choice-box .menu-item > .label { -fx-text-fill: white; }
// Text color of focused item in the list
.choice-box .menu-item:focused > .label { -fx-text-fill: black; }

如果您进一步为ChoiceBox 着色:

// Background color of the control itself
.choice-box {
  -fx-background-color: black;
  -fx-mark-color: orange; // arrow color
}

// Selected item text color on the control itself
.choice-box > .label { -fx-text-fill: white; }

结果将是这样的ChoiceBox

【讨论】:

    猜你喜欢
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    相关资源
    最近更新 更多