Skip to content

Instantly share code, notes, and snippets.

@TheItachiUchiha
Created September 26, 2015 17:18
Show Gist options
  • Save TheItachiUchiha/aeee15daf6eb8250cbe3 to your computer and use it in GitHub Desktop.
Save TheItachiUchiha/aeee15daf6eb8250cbe3 to your computer and use it in GitHub Desktop.
ImageInImageView
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.net.URL;
public class ImageInImageView extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
ImageView imageView = new ImageView();
ScrollPane scrollPane = new ScrollPane(imageView);
TextField textField = new TextField("https://upload.wikimedia.org/wikipedia/commons/f/f7/2006-06-13_2000x3000_chicago_river.jp");
imageView.imageProperty().bind(Bindings.createObjectBinding(() ->
{
URL url = new URL(textField.getText());
if (url != null) {
Image image = new Image(url.toExternalForm());
return image;
} else {
return null;
}
}, textField.textProperty()));
primaryStage.setScene(new Scene(new VBox(10, textField, scrollPane), 500, 400));
primaryStage.show();
}
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