SamC SamC - 10 months ago 73
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);