javafx-8 - 我的 javafx 图形没有显示我创建的按钮上的图像
问题描述
package javafxskel;
import javafx.event.*;
import javafx.scene.image.*;
import javafx.application.*;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import static javafx.scene.control.ContentDisplay.GRAPHIC_ONLY;
import javafx.scene.image.Image;
也许我的进口有问题。我也尝试将文件路径粘贴到new Image("")
public class JavaFXSkel extends Application {
public void init() {
System.out.println("Inside the innit method()");
}
public void start(Stage myStage) {
myStage.setTitle("WINDOW");
FlowPane rootNode = new FlowPane(10, 10);
rootNode.setAlignment(Pos.CENTER);
Scene myScene = new Scene(rootNode, 250, 250);
myStage.setScene(myScene);
我不知道您是否需要了解更多细节,但这是代码
Image picture = new Image("file:pictureIcon.jpeg");
Image save = new Image("file:saveIcon.jpeg");
Label response = new Label("push a button");
Button btnpicture = new Button("Picture", new ImageView(picture));
Button btnsave = new Button("Save", new ImageView(save));
btnpicture.setContentDisplay(GRAPHIC_ONLY);
btnsave.setContentDisplay(GRAPHIC_ONLY);
btnpicture.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent ae) {
response.setText("Picture button");
}
});
btnsave.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent ae) {
response.setText("Save button");
}
});
rootNode.getChildren().add(btnpicture);
rootNode.getChildren().add(btnsave);
rootNode.getChildren().add(response);
myStage.show();
}
解决方案
推荐阅读
- java - 如何使用谓词过滤多个不继承同一个接口的POJO
- .htaccess - .htaccess 重写导致 index.php 不起作用
- c# - 获取 textBlock 的高度时,无论实际高度如何,它都会显示相同的数字
- arrays - 我如何找到两张牌的总和?
- node.js - 监控和刷新 PubSub 批处理发布者队列
- go - Is it safe to write files in mode os.O_APPEND|os.O_WRONLY?
- file - 如何将不同类型的数据存储在一个文件中
- tree - 使 C 不平衡的两个子树是什么?
- html - 链接内的 HTML
- django - “profile_picture”属性没有与之关联的文件