SamC SamC - 2 years ago 157
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
Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download