Planet JFX

Image Viewer Example

118pages on
this wiki
Add New Page
Talk0 Share

This is a simple example of an image viewer that works in JFXPad.

import javafx.ui.canvas.*;
import javafx.ui.*;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

class ImageLoadNode extends CompositeNode {
    attribute url: String;

function ImageLoadNode.composeNode() = 
Group {
    [View {
        content: Button {
            cursor: DEFAULT
            text: "Browse"
            action: operation() {
                var fc = new JFileChooser();
                var filter = new FileNameExtensionFilter("Images", ["jpg", "gif", "png"]);
                var returnVal = fc.showOpenDialog(null);
                if(returnVal == JFileChooser.APPROVE_OPTION) {
                    url = fc.getSelectedFile().toURL().toString();
    View {
        transform: translate(68, 2)
        content: TextField {
            columns: 30
            value: bind url
    ImageView {
        transform: translate(0, 25)
        image: Image { url: bind url }

Canvas {
    content: ImageLoadNode { url: "" }

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.