3

What I wanted to do is replace the standard JavaFX checkBox with my own pictures. I made many searches and I found :

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

But, in both cases, neither does what I want.

4
  • 1
    you cant just change the image. you will need to create your own control, with an own renderer Commented Aug 6, 2013 at 14:11
  • Thanks, but, Is there a way to do that with css ? Commented Aug 6, 2013 at 14:28
  • Sry css can only change design, but the checkbox is not a pickture it is a rendered control without pictures Commented Aug 6, 2013 at 14:42
  • Ok, thanks, gonna take a look to the rendered option Commented Aug 6, 2013 at 14:52

2 Answers 2

4

Here is the CSS I used to replace the checkbox with my own images. This is based off the JavaFX8 Modena stylesheet, but should be fairly close for Caspian. Replace the urls with the location of your images relative to your CSS sheet.

.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");
}
Sign up to request clarification or add additional context in comments.

Comments

3

For a tutorial, please, consult the official documentation. There was a lot of new stuff that was added in 2.2. Also, the Introduction to FXML covers pretty much everything you need to know about FXML. Finally, Hendrik Ebbers made an extremely helpful blog post about custom UI controls.

1 Comment

The "Mastering JavaFX 8 Controls" (guigarage.com/javafx-book) book will contain a chapter about skinning with CSS and a chapter about custom controls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.