【发布时间】:2014-10-26 15:54:37
【问题描述】:
我想让滚动窗格上的图像视图看起来是圆形的。我正在向 Vbox 添加一个图像视图和一个按钮。然后将该 vbox 添加到网格窗格。将网格窗格添加到滚动窗格。
这是我的屏幕截图
这是我的代码
File file = new File("D:\\SERVER\\Server Content\\Apps\\icons");
File[] filelist1 = file.listFiles();
ArrayList<File> filelist2 = new ArrayList<>();
for (File file1 : filelist1) {
filelist2.add(file1);
}
btnar = new ArrayList<>();
for (int i = 0; i < filelist2.size(); i++) {
downloadbtn = new Button("Download");
btnar.add(downloadbtn);
}
System.out.println(filelist2.size());
gridpane.setAlignment(Pos.CENTER);
gridpane.setPadding(new Insets(20, 20, 20,20));
gridpane.setHgap(20);
gridpane.setVgap(20);
ColumnConstraints columnConstraints = new ColumnConstraints();
columnConstraints.setFillWidth(true);
columnConstraints.setHgrow(Priority.ALWAYS);
gridpane.getColumnConstraints().add(columnConstraints);
int imageCol = 0;
int imageRow = 0;
for (int i = 0; i < filelist2.size(); i++) {
System.out.println(filelist2.get(i).getName());
image = new Image(filelist2.get(i).toURI().toString());
pic = new ImageView();
pic.setFitWidth(130);
pic.setFitHeight(130);
pic.setImage(image);
vb = new VBox();
vb.getChildren().addAll(pic, (Button)btnar.get(i));
gridpane.add(vb, imageCol, imageRow);
GridPane.setMargin(pic, new Insets(2, 2, 2, 2));
imageCol++;
// To check if all the 3 images of a row are completed
if (imageCol > 2) {
// Reset Column
imageCol = 0;
// Next Row
imageRow++;
}
【问题讨论】:
-
为什么要在没有 css 的情况下完成它?
-
@ItachiUchiha 那么,你如何在这里使用 css??
-
@James_D 我经历了 [Border-Radius and Shadow on ImageView ](stackoverflow.com/questions/20489908/… 如上所述进行了编辑,但随后我的图像将不会显示在滚动窗格上
标签: image javafx rounded-corners