Created
June 12, 2014 09:57
-
-
Save abhinayagarwal/c8ed36c57dd6b4f44638 to your computer and use it in GitHub Desktop.
Backgroung Color for ImageView/Screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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