SamC SamC - 5 months ago 12x
Java Question

JavaFX add border to ToggleButton graphic

I'm trying to add a border around images in JavaFX

and can't find a good way to do this.

jns jns

You can add the ImageView to a StackPane and use the StackPane as the graphic node of the ToggleButton. Then you can apply a border to the StackPane:

    ImageView graphic = new ImageView(imageUrl);
    StackPane pane = new StackPane(graphic);
    pane.setStyle("-fx-border-color: red; -fx-border-width:4; ");

    ToggleButton toggleButton = new ToggleButton("", pane);