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();
}