Image width binding in JavaFX

I have a very basic application that I believe should change the width of an image, but it does nothing ... can someone tell me why when I click on the image, nothing happens to the image?

(note that the image itself doesn't really matter, I'm just trying to figure out how to shrink and grow, and the image in JavaFX)

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.input.MouseEvent;

var w:Number = 250;

Frame {
    title: "Image View Sample"
    width: 500
    height: 500
    closeAction: function() { 
        java.lang.System.exit( 0 ); 
    }
    visible: true

    stage: Stage {
        content: [
            ImageView {
                x: 200;
                y: 200;
                image: Image {
                    url: "{__DIR__}/c1.png"
                    width: bind w;
                }

                onMouseClicked: function( e: MouseEvent ):Void {
                    w = 100;
                }
            }
        ]
    }
}

      

Thanks heaps!

0


source to share


2 answers


Try to bind the scale attributes:



import java.lang.System;
import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.input.MouseEvent;

var w:Number = 1;

Frame {
    title: "Image View Sample"
    width: 500
    height: 500
    closeAction: function() { 
        java.lang.System.exit( 0 ); 
    }
    visible: true

    stage: Stage {
        content: [
            ImageView {
                x: 200
                y: 200
                anchorX:200 
                anchorY:200
                scaleX:bind w
                scaleY:bind w
                image: Image {
                    url: "{__DIR__}/time.png"                    
                }

                onMouseClicked: function( e: MouseEvent ):Void {
                    w += 0.1;                    
                }
            }
        ]
    }
}

      

+1


source


Thanks for the reply, sorry for the delay coming back to you, but it turns out that all you have to do is link the image itself:

image: bind Image {
    url: "{__DIR__}/time.png"
    width: w;
}

      



And that seems to do a trick that I personally find a little overshot, but hey it works

+1


source







All Articles