2 Replies Latest reply: Feb 14, 2013 4:02 AM by dmv RSS

    Using image resources instead of CSS for JavaFx checkbox state

    dmv
      Has anyone used a series of png image resources instead of CSS for the graphics in the JavaFX checkbox? I have a checkbox tree where I would like to colour certain checkboxes according to the tree contents.

      Thanks in advance ...
        • 1. Re: Using image resources instead of CSS for JavaFx checkbox state
          David Grieve
          You can use -fx-background-image to style the "mark" which is shown when the checkbox is selected. You can also style the "box" in which the "mark" is contained.
          The check mark itself is specified in caspian.css as a shape, so if you don't want the check mark, set it to null.
          .check-box > .box > .mark {
              -fx-shape: null;
          }
          
          .check-box:selected > .box > .mark {
              -fx-background-image: url("images/duke.png");
          }
          You can use multiple style classes to style the check box according to the tree content. You'd probably want to use a cell factory to set the style-class on the CheckBox (see TreeView#setCellFactory).
          .check-box.red > .box {
              -fx-color: red;
          }
          • 2. Re: Using image resources instead of CSS for JavaFx checkbox state
            dmv
            Thank you so much for a very helpful reply and my apologies for a delayed reply. I had visions of doing tedious things with css but you have given me a way forward.