Skip to content

Instantly share code, notes, and snippets.

@wuiler
Created November 13, 2020 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wuiler/8387fc6b367eb666b33ff822f1b433fe to your computer and use it in GitHub Desktop.
Save wuiler/8387fc6b367eb666b33ff822f1b433fe to your computer and use it in GitHub Desktop.
JavaFX Image Sample
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
public class ImageExample extends Application {
@Override
public void start(Stage stage) throws java.io.FileNotFoundException {
Image image = new Image(new java.io.FileInputStream("javanetar.jpg"));
ImageView imageView = new ImageView(image);
Group root = new Group(imageView);
Scene scene = new Scene(root, 600, 500);
stage.setTitle("Welcome to www.java.net.ar !");
stage.setMaximized(true);
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
launch(args);
}
}
@wuiler
Copy link
Author

wuiler commented Nov 13, 2020

This use JavaFX 11. See https://openjfx.io/ for more info:

You need to set JAVAFX, JAVAFX_MODS, JAVA_HOME and change the path where your java environment is. For example:

export JAVAFX=/opt/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/
export JAVAFX_MODS=/opt/openjfx-11.0.2_linux-x64_bin-jmods/javafx-jmods-11.0.2/
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

To compile:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java --module-path $JAVAFX_MODS --add-modules javafx.controls ImageExample

To run:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java --module-path $JAVAFX --add-modules javafx.controls ImageExample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment