Search code examples
javajavafxgeometryfillfxml

How can I make a ring in JavaFX (fxml)


I need to make a ring in JavaFX using fxml. It will be circling an item on an image beneath it. I can make a circle, but it seems to be required to have a fill. I can adjust the opacity, but that adjusts the opacity of both the fill and the circle.

I don't have image editing software at work (and I can't just install gimp) so I can't create an image and use an ImageView. Paint won't let you save images without backgrounds.

It seems like such a simple task to create a circle without a fill. Am I missing something?

Thanks


Solution

  • You can use the circle for that, just make sure to add this in your CSS:

     .circle {
     /* The numbers before the alpha doesn't matter.  
        As you imagine this would be green if the alpha was higher
        rgba(RED,GREEN,BLUE,ALPHA); RGBA
     */ 
             -fx-fill:  rgba(0,255,0,0);
    
     }
    

    if you want to have other circles you can specify an specific css class for this:

     .ring {
          -fx-fill:  rgba(0,255,0,0);
     }
    

    Then:

    circle.getStyleClass().add("ring");