Skip to content

Instantly share code, notes, and snippets.

@abhinayagarwal
Created June 12, 2014 09:57
Show Gist options
  • Save abhinayagarwal/c8ed36c57dd6b4f44638 to your computer and use it in GitHub Desktop.
Save abhinayagarwal/c8ed36c57dd6b4f44638 to your computer and use it in GitHub Desktop.
Backgroung Color for ImageView/Screen
public class ImageViewBackgroundColor extends Application {
@Override
public void start(Stage stage) throws Exception {
try {
stage.setWidth(Screen.getPrimary().getBounds().getWidth());
stage.setHeight(Screen.getPrimary().getBounds().getHeight());
BorderPane borderPane = new BorderPane();
ImageView imageView = new ImageView();
Image image = new Image(getClass().getResource("huskar.jpg")
.toString());//replace your image file here
imageView.setImage(image);
imageView.setStyle("-fx-background-color: BLACK");
imageView.setFitHeight(stage.getHeight() - 10);
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
borderPane.setCenter(imageView);
Scene scene = new Scene(borderPane, Color.BLACK);
stage.setScene(scene);
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment