我寫了絕對路徑 但是不好使
public class Demo1 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
//Button btn = new Button("Say Hi!");
Button btn = new Button("Say Hi!", new ImageView("D:\\JavaFX Workspace 1.0\\JavaFx\\src\\iamges\\search-label.png"));
btn.setOnAction((e) -> {
System.out.println("Say Hi!");
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
換一個bmp看看,是不是不支持png