0

I want to make the imageviews on scrollpane to look rounded in shape..I'm adding an imageview and a button to a Vbox.Then that vbox to a gridpane.Gridpane is added to scrollpane.

I made use of this as well

Border-Radius and Shadow on ImageView

here's a screen shot:enter image description here

here's my code:

 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);

                clip=new Rectangle(pic.getFitWidth(), pic.getFitWidth());
                clip.setArcHeight(20);
                clip.setArcWidth(20);
                pic.setClip(clip);

                SnapshotParameters parameters=new SnapshotParameters();
                parameters.setFill(Color.TRANSPARENT);
                WritableImage image=pic.snapshot(parameters, null);

                pic.setClip(null);
                pic.setEffect(new DropShadow(20,Color.BLACK));

            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++;

            }
Community
  • 1
  • 1

0 Answers0