JavaFX 中的图像宽度绑定
我有一个非常基本的应用程序,我相信它应该改变图像的宽度,但它什么也没做...任何人都可以告诉我为什么当我单击图像时,图像没有任何反应?
(注意,图像本身并不重要,我只是想弄清楚如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试绑定比例属性:
Try to bind scale attributes:
感谢您的回复,很抱歉延迟回复您,但事实证明您所需要做的就是绑定图像本身:
这似乎可以解决问题,我个人认为这有点误导,但是嘿,有用
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:
And that seems to do the trick, which personally I find a bit missleading, but hey, it works