Lazy loading of images in scrollpane

Tomas Mikula tomas.mikula at gmail.com
Mon Jul 13 19:15:50 UTC 2015


Or use Flowless
https://github.com/TomasMikula/Flowless

Tomas
 On Jul 13, 2015 2:36 PM, "Tom Schindl" <tom.schindl at bestsolution.at> wrote:

> Use a ListView ;-) Unfortunately the base class (VirtualFlow is not
> public API)
>
> Tom
>
> On 13.07.15 20:19, Christian Krampenschiesser wrote:
> > Hi all,
> >
> > I am trying around since some time to load images when they are visible
> in
> > a scollpane.
> > However the only solution I got so far is quite complicated and done via
> > checking the bounds in the scene.
> > However sometimes the calculated bounds of the item in the scene are way
> > out of the scene.
> > I am really looking for a simpler solution then my current one.
> > My tests are fine so far with small amounts of thumbnails. however with
> big
> > scenes (~3000 thumbnails) everything goes wrong :(
> > But if there is none maybe someone can point out my wrong bounding box
> > calculations and why they are wrong. It seems I didn't understand
> > everything correctly:
> >
> > protected SimpleObjectProperty<GalleryItem> item = new
> > SimpleObjectProperty<>();//contains, path and loads thumbnail + real
> > image
> >
> > ....
> >
> > button.localToSceneTransformProperty().addListener(new
> > ChangeListener<Transform>() {//button has an imageview which displays
> > the thumbnail
> >   @Override
> >   public void changed(ObservableValue<? extends Transform> observable,
> > Transform oldValue, Transform newValue) {
> >     Point2D point = button.localToScene(button.getLayoutX(),
> > button.getLayoutY());
> >     Scene scene = button.getScene();
> >
> >     boolean isLayoutedCorrectly = button.getWidth() > 100 &&
> > button.getHeight() > 100;//hack to execute after layouting, otherwise
> > all items are visible
> >
> >     if (scene != null && button.getParent() != null &&
> > isLayoutedCorrectly && armed) {//armed is set 100ms after adding all
> > buttons to a flowpane in a scrollpane
> >       BoundingBox sceneBox = new BoundingBox(scene.getX(),
> > scene.getY(), scene.getWidth(), scene.getHeight());
> >       BoundingBox buttonBox = new BoundingBox(point.getX(),
> > point.getY(), button.getWidth(), button.getHeight());
> >
> >       if (sceneBox.intersects(buttonBox)) {//visible
> >         if (imageView.getImage() == null) {
> >           log.debug("Showing {}", button.getText());
> >           Image image = item.get().loadThumbNail();
> >           if (image != null) {
> >             imageView.setImage(image);
> >             imageView.setFitHeight(image.getHeight());
> >             imageView.setFitWidth(image.getWidth());
> >           }
> >         }
> >       }
> >     }
> >   }
> > });
> >
> >
> > Thanks!
> >
> > Christian
> >
>
>
> --
> Thomas Schindl, CTO
> BestSolution.at EDV Systemhaus GmbH
> Eduard-Bodem-Gasse 5-7, A-6020 Innsbruck
> http://www.bestsolution.at/
> Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
>


More information about the openjfx-dev mailing list