聚焦并选择项目时的JavaFX ComboBox样式

时间:2018-09-25 00:51:03

标签: javafx-8

我一直在尝试取消组合框的样式。基本上,我希望它完全透明,只显示文本和箭头。 我已经做到了:

.agent-status-combo .arrow-button, .agent-status-combo .arrow-button:hover {
    -fx-background-color: transparent, transparent, transparent, transparent;
}
.agent-status-combo, .agent-status-combo:hover, agent-status-combo:focused, .agent-status-combo:showing, .agent-status-combo:selected, .agent-status-combo:filled  {
    -fx-font: 14px "Roboto";
    -fx-background-color: transparent, transparent, transparent, transparent;
}
.agent-status-combo:hover > .arrow-button {
    -fx-background-color: transparent, transparent, transparent, transparent;
}
.agent-status-combo .arrow {
    -fx-background-color: #FFFFFF;
}

.agent-status-combo .cell, .agent-status-combo .cell:selected, .agent-status-combo .cell:focused, .agent-status-combo .cell:selected:filled, .agent-status-combo .cell:filled:selected, .agent-status-combo .cell:focused:selected {
    -fx-background-color: transparent, transparent, transparent, transparent; 
    -fx-text-fill: white;
}

.agent-status-combo .list-cell:selected, .agent-status-combo .list-cell:focused, .agent-status-combo .list-cell:selected:filled, .agent-status-combo .list-cell:filled:selected, .agent-status-combo .list-cell:focused:selected {
    -fx-background-color: transparent, transparent, transparent, transparent; 
}

从选择器的过大功能中可以看出,我有一个问题。 当组合键聚焦时,我无法获得所有这些可爱的规则来工作……它只是恢复为默认样式。

有人遇到过吗?

2 个答案:

答案 0 :(得分:0)

您可以为此使用jfoenix.jar。 只需将其安装在Scene Builder和您的项目中。 然后,您可以使用其组件,例如组合框等。 将组合框设为透明后,可以使用以下示例代码:      .jfx-combo-box{ -jfx-focus-color: transparent; -jfx-unfocus-color: transparent; } .jfx-combo-box:focused{ -fx-background-color: red; } .jfx-combo-box:selected{ -fx-background-color: red; }

答案 1 :(得分:0)

使它不能集中遍历就解决了这个问题。是的,它可以防止使用选项卡浏览UI,但这不是问题。

相关问题