这个问题在这里已有答案:
我必须创建一个带有来自某个URL的背景图像的javafx按钮 . 图像显示完美 . 但问题是图像不圆润 . 图像显示为其原始形状 . 但我需要创建按钮作为图像的圆形视图 . 我怎样才能做到这一点?
这是我试过的代码
Image cameraIcon = new Image("//url");//image will be from url
ImageView cameraIconView = new ImageView(cameraIcon);
cameraIconView.setFitHeight(120);
cameraIconView.setFitWidth(120);
cameraIconView.setStyle(""
+ "-fx-border-color: black;"
+ "-fx-border-style: solid;"
+ "-fx-border-width: 10;"
+ "-fx-border-radius: 10 10 10 10;"
);
Button button;
button.setGraphic(cameraIconView);
button.setStyle("-fx-base: coral;");
button.setStyle(
"-fx-background-radius: 50em; "
+ "-fx-min-width: 60px; "
+ "-fx-min-height: 60px; "
+ "-fx-max-width: 130px; "
+ "-fx-max-height: 60px;"
);
1 回答
尝试用css风格