JavaFX 中的图像宽度绑定

发布于 2024-07-09 04:55:01 字数 908 浏览 5 评论 0原文

我有一个非常基本的应用程序,我相信它应该改变图像的宽度,但它什么也没做...任何人都可以告诉我为什么当我单击图像时,图像没有任何反应?

(注意,图像本身并不重要,我只是想弄清楚如何在 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;
                }
            }
        ]
    }
}

谢谢!

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

(note, the image itself doesnt really matter, Im just trying to figure out how to shrink and grow and 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2024-07-16 04:55:01

尝试绑定比例属性:

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;                    
                }
            }
        ]
    }
}

Try to bind 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;                    
                }
            }
        ]
    }
}
在巴黎塔顶看东京樱花 2024-07-16 04:55:01

感谢您的回复,很抱歉延迟回复您,但事实证明您所需要做的就是绑定图像本身:

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

这似乎可以解决问题,我个人认为这有点误导,但是嘿,有用

Thanks for the reply, sorry for the delay getting back to you, but it turns out that all you need to do is to bind the image itself:

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

And that seems to do the trick, which personally I find a bit missleading, but hey, it works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文