GridPane(ScrollPaneにネストされています)を作成して、GridPaneに動的にセルを追加したいとします。各セルには、BackgroundImage、いくつかのラベル、チェックボックスを持つVBoxが含まれています。問題は、GridPaneに数百のVBoxが含まれている可能性があります。私のケースでは、約300個のVBoxがあり、このVBoxesでGridpaneの応答時間が非常に悪くなります。 CheckBoxでインスタンスをクリックすると、CheckBoxが選択/選択解除されるまで数秒かかります。これにより、プログラムはかなり使用できなくなります。背景画像なしでGridPaneの応答時間は完璧ですので、私はここでの問題は、画像がGridPaneのJavaFxイメージがパフォーマンスを大幅に低下させる
ある。これは、VBoxのを作成するための私のコードであることを知っている:
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;
}
私はすでに代わりにImageViewのを使用しようとしましたBackgroundImageの残念ながら、ImageViewのパフォーマンスは、BackgroundImageほど劣っています。