Load Image from URL : ImageView « JavaFX « Java
- Java
- JavaFX
- ImageView
Load Image from URL
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.GroupBuilder;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.ImageViewBuilder;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
String imageSource = "http://yourImageURL";
ImageView imageView = ImageViewBuilder.create()
.image(new Image(imageSource))
.build();
Group myGroup = GroupBuilder.create()
.children(imageView)
.build();
root.getChildren().add(myGroup);
primaryStage.setScene(new Scene(root, 500, 400));
primaryStage.show();
}
}
Related examples in the same category