我必须使用某个网址创建一个带有背景图片的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;"
);
答案 0 :(得分:1)
尝试使用css样式
.btnHome {
-fx-background-image: url("/images/btnHomeHover.png");
-fx-background-size: 50px, 50px;
-fx-background-repeat: no-repeat;
-fx-background-position: center;
-fx-border-radius: 30;
}