JavaFX - 用图像替换标准CheckBox

时间:2013-08-06 14:08:40

标签: css checkbox javafx-2

我想要做的是用我自己的图片替换标准的JavaFX checkBox。 我做了很多搜索,然后发现:

  • -fx-graphic:url
  • -fx-background-image:url

但是,在这两种情况下,我都不想做。

2 个答案:

答案 0 :(得分:4)

这是我用来替换我自己的图像的复选框的CSS。这是基于JavaFX8摩德纳样式表,但对于凯斯宾来说应该非常接近。将网址替换为相对于CSS工作表的图像位置。

.check-box>.box {
  -fx-background-insets: 0;
  -fx-background-radius: 0;
  -fx-background-color: transparent;
}

.check-box>.box>.mark {
  -fx-background-image: url("unmarked.png");
  -fx-background-position: center;
  -fx-background-repeat: stretch;
  -fx-shape: none;
}

.check-box:selected>.box>.mark{
  -fx-background-color: transparent;
  -fx-background-image: url("marked.png");
}

答案 1 :(得分:3)

有关教程,请参阅the official documentation。在2.2中添加了很多new stuff。此外,Introduction to FXML涵盖了您需要了解的有关FXML的所有内容。最后,Hendrik Ebbers对自定义UI控件提出了非常有帮助的blog post

相关问题