样式javafx复选框

时间:2017-04-23 01:50:37

标签: java javafx

我已尝试将以下样式应用于我的CheckBox

.check-box .box {
    -fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-white;
}

.check-box:selected .mark {
    -fx-background-color: -fx-colour-white;
}

.check-box:selected .box {
    -fx-background-color: -fx-blue;
}

目标是使用带有灰色边框的白色复选框,并选中复选框以获得蓝色背景和白色勾号。当我应用这些样式时,我得到了我想要的结果。然而,在执行以下步骤时会发生奇怪的事情:
1-单击复选框以选择
2-单击复选框以取消选择
该复选框消失,只有在我单击窗格中的其他位置时才会再次出现。

首次渲染时,您可以看到复选框下方的图像,然后选中复选框。

Checkbox in normal state Selected Checkbox Deselected Checkbox

1 个答案:

答案 0 :(得分:3)

我认为问题不是来自你的 StyleSheets ,我认为这是由于 Java代码中的操作不当,你说:

  

复选框消失,只有在我点击面板中的其他位置

时才会再次显示

首先从你的 Pane 开始,看看是否有相关的事件,并且关于样式,你的方法几乎正确,这就是我将要进行的方式:

.check-box .box {

-fx-background-color: white;
-fx-border-color:grey;
-fx-border-radius:3px; 

}

.check-box:selected .mark {

-fx-background-color: white;

}

.check-box:selected .box {

-fx-background-color: #28a3f4;
}
祝你好运!

相关问题