【发布时间】:2014-05-30 16:34:05
【问题描述】:
我正在尝试使用 JavaFx 构建一个简单的图像查看器,其工作原理类似于:
Viewer viewer = new Viewer("path/to/file.jpg");
我已经尝试了以下代码行,但它不起作用。
public class Viewer extends Application {
private String filePath;
public Viewer(String filePath) {
this.filePath = filePath;
}
@Override
public void start(Stage stage) {
// load the image
Image image = new Image("file:" + this.filePath);
// simple displays ImageView the image as is
ImageView iv1 = new ImageView();
iv1.setImage(image);
Group root = new Group();
Scene scene = new Scene(root);
HBox box = new HBox();
box.getChildren().add(iv1);
root.getChildren().add(box);
stage.setTitle(this.filePath);
stage.setWidth(415);
stage.setHeight(200);
stage.setScene(scene);
stage.sizeToScene();
stage.show();
}
}
有向 JavaFx 应用程序传递参数的标准方法吗?
【问题讨论】: