我有一个Image
对象,并希望将其设置为 Javafx Button的背景
Image image_here = //Image from API call
Button btn = new Button();
btn.setShape(new Circle(25));
btn.setMinSize(50, 50);
btn.setMaxSize(50, 50);
我试过了
btn.setGraphic(image_here); //this causes image to go out of button boundary. Not Ideal for my usecase.
及以下方法
BackgroundImage icon_background = new BackgroundImage(image_here,
BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
BackgroundPosition.CENTER, BackgroundSize.DEFAULT);
Background background = new Background(icon_background);
btn.setBackground(background);
可以使用
设置背景setStyle btn.setStyle("-fx-background-image: url('" + image_here+ "');");
但在尝试通过fx-background-image
添加图片之前,我不确定是否需要将图片转换为其他形式