You may prefer to use DropShadow
effect to show border:
@Override
public void start( final Stage primaryStage )
{
DropShadow ds = new DropShadow( 20, Color.AQUA );
ImageView imageView = new ImageView( "http://vignette3.wikia.nocookie.net/forgeofempires/images/b/b8/Castel_del_Monte.png" );
imageView.setOnMouseClicked( ( MouseEvent event ) ->
{
imageView.requestFocus();
} );
imageView.focusedProperty().addListener(( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue ) ->
{
if ( newValue )
{
imageView.setEffect( ds );
}
else
{
imageView.setEffect( null );
}
});
final Scene scene = new Scene(
new VBox( imageView,
new Button( "When you focus on me, the imageview looses its shadow effect" ) ),
500, 200 );
primaryStage.setScene( scene );
primaryStage.show();
}
When the imageview is clicked we request a focus on it, which triggers the focusProperty
change listener and sets the effect, and when the imageview looses its focus (either by hitting TAB or clicking the below button) the effect cleared.