GridPane'e dinamik olarak hücreler eklediğim bir GridPane (bir ScrollPane'de yuvalanmış) oluşturmak istiyorum. Her bir hücre bir BackgroundImage, birkaç Etiket ve bir Checkbox içeren bir VBox içerir. Sorun şu ki GridPane birkaç yüz VBox içerebilir, benim durumumda yaklaşık 300 VBox var ve bu VBox'larla Gridpane'in tepki süresi gerçekten çok kötü. Örneğin bir CheckBox'ta tıklattığımda, CheckBox'un seçili/seçili olmayana kadar birkaç saniye sürmesi programımı oldukça kullanılamaz hale getirir. BackgroundImage olmadan GridPane tepki süresi mükemmel, bu yüzden buradaki sorun GörüntülerJavaFx görüntüleri, performansı yavaş yavaş yavaşlatıyor
Bu vbox oluşturmak için benim Kod olduğunu biliyoruz:
private VBox createAlbumVBox(Album album) {
VBox container = new VBox();
container.setAlignment(Pos.BOTTOM_LEFT);
CheckBox checkBox = new CheckBox();
Label labelAlbum = new Label(album.getName());
Label labelArtist = new Label(album.getArtistName());
labelAlbum.setStyle("-fx-text-fill: #272727");
labelArtist.setStyle("-fx-text-fill: #272727");
Background background;
if(album.getCover() != null)
{
byte[] coverData = album.getCover();
Image image = new Image(new ByteArrayInputStream(coverData));
BackgroundSize bg = new BackgroundSize(100,100,true,true,true,false);
BackgroundImage backgroundImage = new BackgroundImage(image,BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT,BackgroundPosition.CENTER,bg);
background = new Background(backgroundImage);
}
else
{
Image image = new Image("/ressources/covers/default-cover.png");
BackgroundSize bg = new BackgroundSize(100,100,true,true,true,false);
BackgroundImage backgroundImage = new BackgroundImage(image,BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT,BackgroundPosition.CENTER,bg);
background = new Background(backgroundImage);
}
checkBox.setOnMouseClicked(e -> {
if (checkBox.isSelected()) {
album.getTitles().forEach(t -> t.setReadyToSync(true));
} else {
album.getTitles().forEach(t -> t.setReadyToSync(false));
}
});
container.setBackground(background);
HBox hBox = new HBox();
hBox.getChildren().addAll(labelAlbum, labelArtist, checkBox);
hBox.setPrefHeight(30);
hBox.setStyle("-fx-background-color: rgba(255, 255, 255, 0.4)");
container.getChildren().addAll(hBox);
return container;
}
Zaten bunun yerine bir ImageView kullanmaya çalıştı Bir BackgroundImage. Ne yazık ki, bir ImageView ile performans bir BackgroundImage kadar zayıf.