How to dynamically load an Image into a TableView when its row/cell becomes visible?

Hi,
I am building an application that shows tables with large amounts of data containing columns that should display a thumbnail. However, this thumbnail is supposed to be loaded in the background lazily, when a row becomes visible because it is computationally too expensive to to this when the model data is loaded and typically not necessary to retrieve the thumbnail for all data that is in the table.
I have done the exact same thing in the past in a Swing application by doing this:
Whenever the model has changed or the vertical scrollbar has moved:
- Render a placeholder image in the custom cell renderer for this JTable if no image is available in the model object representing the corresponding row
- Compute the visible rows by using getVisibleRect and rowAtPoint methods in JTable
- Start a background thread that retrieves the image for the given rows and sets the resulting BufferedImage in a custom Model Object that was used in the TableModel (if not already there because of an earlier run)
- Fire a corresponding model change event in the EDT whenever an image has been retrieved in the background thread so the row is rendered again
Btw. the field in the model class holding the BufferedImage was a weak reference in this case so the memory can be reclaimed as needed by the application.
What is the best way to achieve this behaviour using a JFX TableView? I have so far failed to find anything in the API to retrieve the visible items/rows. Is there a completely different approach available/required that uses the Cell API? I fail to see it so far.
Thanks in advance for any hints here.

Here’s what I have tried so far:
I have defined a property in my model object that contains a weak reference to the image that is expensive to load. I have modeled that reference as an inner class to the object so I have a reference to its enclosing object. That is necessary because my cell factory otherwise has no access to the enclosing model object, which it needs to trigger loading the image in the background.
The remaining problems I have is, that I don’t have sufficient control over the loading process, i.e. I need to delay the loading process until scrolling has stopped and abort it as soon as the user starts scrolling again and the visible content changes. Imagine that loading an image for a table row (e.g. a thumbnail for a video) takes 200ms to load and a user quickly scrolls through a few hundred records and then stops. With my current set-up, the user has to wait for all loading processes that were triggered in the cell factories to finish until the thumbnails of the records they are looking at will appear (imagine an application like finder to be implemented like that, it would simply suck UX-wise). In my swing application a background thread that loads images for the visible records is triggered with a delay and stopped as soon as the visible content changes. This works well enough for a good user experience. I don’t see how I can do this based on the cell API. It is nice to have all this abstracted away but in this case I do not see how I can achieve the same user experience as in my swing application.
I also tried registering a change listener to the TreeCell’s visible property to make that control the image loading but I don’t seem to get any change events at all when I do that.
I must be missing something.

Similar Messages

  • How can i load a image into a midlet?

    Hi, i placed the png file together wif the midlet in the src directory.
    Image img = Image.createImage("title.png");
    I tried the above code but when i try to load the image in got this error
    Failed loading image.
    anione can help?

    just place your file in /res/ directory not in /src/

  • How can I load preview images into an extra file?

    Hi,
    I've got a question concerning those preview images. I wrote a plugin which uses the actual paths of the photos in the catalog an stores those paths of each photo into a log file. Then an external program has access to that file for further handling. So now I would like to use preview photos instead of the raw images. First, because the user might want to use the picture he/she edited with Lightroom; And then because of the size.Processing a preview image of level 5 would be more efficient than the original photo.
    So how can I get those preview photos? And more important: is it possible to store them in an extra file in a jpg format for instance, so that an external program can make use of them?

    Look at source code in PreviewExporter plugin.
    robcole.com - PreviewExporter

  • How to load an image into blob in a custom form

    Hi all!
    is there some docs or how to, load am image into a database blob in a custom apps form.
    The general idea is that the user has to browse the local machine find the image, and load the image in a database blob and also in the custom form and then finally saving the image as blob.
    Thanks in advance
    Soni

    If this helps:
    Re: Custom form: Take a file name input from user.
    Thanks
    Nagamohan

  • Loading an image into an Applet from a JAR file

    Hello everyone, hopefully a simple question for someone to help me with!
    Im trying to load some images into an applet, currently it uses the JApplet.getImage(url) method just before registering with a media tracker, which works but for the sake of efficiency I would prefer the images all to be contained in the jar file as oppossed to being loaded individually from the server.
    Say I have a class in a package eg, 'com.mydomain.myapplet.class.bin' and an images contained in the file structure 'com.mydomain.myapplet.images.img.gif' how do I load it (and waiting for it to be loaded before preceeding?
    I've seen lots of info of the web for this but much of it is very old (pre 2000) and im sure things have changed a little since then.
    Thanks for any help!

    I don't touch applets, so I can't help you there, but here's some Friday Fun: tracking image loading.
    import java.awt.*;
    import java.awt.image.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.imageio.event.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class ImageLoader extends SwingWorker<BufferedImage, Void> {
        private URL url;
        private JLabel target;
        private IIOReadProgressAdapter listener = new IIOReadProgressAdapter() {
            @Override public void imageProgress(ImageReader source, float percentageDone) {
                setProgress((int)percentageDone);
            @Override public void imageComplete(ImageReader source) {
                setProgress(100);
        public ImageLoader(URL url, JLabel target) {
            this.url = url;
            this.target = target;
        @Override protected BufferedImage doInBackground() throws IOException {
            ImageInputStream input = ImageIO.createImageInputStream(url.openStream());
            try {
                ImageReader reader = ImageIO.getImageReaders(input).next();
                reader.addIIOReadProgressListener(listener);
                reader.setInput(input);
                return reader.read(0);
            } finally {
                input.close();
        @Override protected void done() {
            try {
                target.setIcon(new ImageIcon(get()));
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
        //demo
        public static void main(String[] args) throws IOException {
            final URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot.jpg");
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch(url);
        static void launch(URL url) {
            JLabel imageLabel = new JLabel();
            final JProgressBar progress = new JProgressBar();
            progress.setBorderPainted(true);
            progress.setStringPainted(true);
            JScrollPane scroller = new JScrollPane(imageLabel);
            scroller.setPreferredSize(new Dimension(800,600));
            JPanel content = new JPanel(new BorderLayout());
            content.add(scroller, BorderLayout.CENTER);
            content.add(progress, BorderLayout.SOUTH);
            JFrame f = new JFrame("ImageLoader");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(content);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            ImageLoader loader = new ImageLoader(url, imageLabel);
            loader.addPropertyChangeListener( new PropertyChangeListener() {
                 public  void propertyChange(PropertyChangeEvent evt) {
                     if ("progress".equals(evt.getPropertyName())) {
                         progress.setValue((Integer)evt.getNewValue());
                         System.out.println(evt.getNewValue());
                     } else if ("state".equals(evt.getPropertyName())) {
                         if (SwingWorker.StateValue.DONE == evt.getNewValue()) {
                             progress.setIndeterminate(true);
            loader.execute();
    abstract class IIOReadProgressAdapter implements IIOReadProgressListener {
        @Override public void imageComplete(ImageReader source) {}
        @Override public void imageProgress(ImageReader source, float percentageDone) {}
        @Override public void imageStarted(ImageReader source, int imageIndex) {}
        @Override public void readAborted(ImageReader source) {}
        @Override public void sequenceComplete(ImageReader source) {}
        @Override public void sequenceStarted(ImageReader source, int minIndex) {}
        @Override public void thumbnailComplete(ImageReader source) {}
        @Override public void thumbnailProgress(ImageReader source, float percentageDone) {}
        @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {}
    }

  • How do I load an image in WEB-INF?

    How do I load an image from WEB-INF with JSP's? I'm using Glassfish and
    NB.
    Filter code:
    String path = filterConfig.getServletContext().getContextPath();
    contextPath = "http://localhost:8080" + context + path;
    String duke = contextPath + "/duke.gif";
    which results in the following html:
    <img src="http://localhost:8080/WebApplication/duke.gif">
    Which is fine, but any user gets to access that image. I want to move
    the image to WEB-INF so that it's not accessible for users.
    see also:
      NetBeans Forums - how to load an image from WEB-INF?

    No i dont think so..... I need to download the jar file through the JNLP which contains those image files.
    Only then the JNLPClassLoader returns the Image file otherwise it returns null.
    (actually i assumed, it loads all those files into it and keeps it as the Resources. I don know whether it is right or not..)
    eg., I download my img.jar in C:\Downloads using JNLPClassLoader which contains New.gif.
    getClass().getResource("New.gif") exactly returns the URL C:\Downloads\img.jar!\New.gif.
    But my ClassLoader returns null for this getClass().getResource("New.gif").
    I also tried calling getClass().getResource("C:\Downloads\img.jar!\New.gif") It simply returns null.
    Im sure that I have the Image file in that path.

  • How do I Place an image into the center of an activated artboard in CC?

    I have just upgraded to CC from CS6. In CS6, I could activate an artboard (double click it in the Artboard panel) and then Place an image, which would by default go into the center of the artboard.
    With CC, it "loads" the image into the cursor which I then need to Place by clicking somewhere.
    How can I get it to either behave as it did in CS6, or customize to load it into the center when I click, such as with a modifier key?
    Thanks!

    Hi,
    With the Window > Allign panel,
    You can select the option to allign to selection or to Artboard.
    When you select "to Artboard" you schould be able to use the Allign option to get it centerred.
    See preview bellow.
    Hope this helps.

  • How do I insert an image into a quetsion (post)

    What are Mozilla code-structure in new posts.?
    How do I insert an image into a new post?
    Thank you

    cor-el said
    If the image is on another server then we prefer to have a link instead of the real image in case it is a large image and we've already seen it or do not want to wait for it to load (server may be slow).
    I do not know what any of this means.
    I have a single laptop connected to the internet.
    So far I have worked out how to upload an image to a thread-reply by copying the uploaded file "path" and pasting it onto the reply
    and then after the reply is posted there are two incidence of each image
    1. the URL
    2. the image at the bottom of the reply
    I am a newbie so would appreciate any feedback
    (Firefox window controls have disappeared (Clean installed v18 5 days ago). Have logged another thread/reply on this forum)
    Thanks

  • How do i load an image through XML?

    Hi.
    My code is below. What I am trying is to dinamically load images from xml. I attach the holder from the library, and when i try to target it and addChild to him i get an error:
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
    xmlLoader.load(new URLRequest("links.xml"));
    var xmlLength:int;
    var iconPos:Number = 0;
    function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    var xmlLength = xmlData.link.length();
    for (var i=0; i<xmlLength; i++) {
    var d:MovieClip = new icon();
    content_mc.addChild(d);
    d.name = "d"+i;
    var target:DisplayObject = content_mc.getChildByName("d"+i);
    var ldr:Loader = new Loader();
    ldr.load(new URLRequest(xmlData.link[i].icon));
    target.addChild(ldr);
    How can i make this happen and load the image into it's holder?
    Thank you.

    Code from adobe's sample packages cut&&paste&&edit:
    AS4 code:
    import flash.events.IOErrorEvent;
    var fotoElenco:Array;
    var fotoXML:XML;
    var fotoURLRequest:URLRequest=new URLRequest();
    var fotoURLLoader:URLLoader=new URLLoader();
    var fotoLoader:Loader=new Loader();
    var fotoPosition:Number=0;
    var errorMessage:TextField=new TextField();
    caricaFoto();
    function caricaFoto():void
        addChild(errorMessage);
        fotoURLRequest.url="gallery.xml";
        fotoURLLoader.load(fotoURLRequest);
        fotoURLLoader.addEventListener(Event.COMPLETE, showFoto);
        fotoURLLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventXML);
    function ioErrorEventXML(event:IOErrorEvent):void
        manageErrorMessage(true, 0);
    function manageErrorMessage(val:Boolean, num:Number):void
        if(val && num==0){
            errorMessage.x=stage.stageWidth/2;
            errorMessage.y=stage.stageHeight/2;
            errorMessage.text="Errore caricamento file XML";
        if(val && num==1){
            errorMessage.x=stage.stageWidth/2;
            errorMessage.y=stage.stageHeight/2;
            errorMessage.text="Errore caricamento file IMMAGINE";
    function showFoto(event:Event):void
        fwd_mc.buttonMode=true;
        back_mc.buttonMode=true;
        back_mc.addEventListener(MouseEvent.CLICK, manageFoto);
        fwd_mc.addEventListener(MouseEvent.CLICK, manageFoto);
        fotoElenco=new Array();
        fotoXML=XML(fotoURLLoader.data);
        for each(var prop:XML in fotoXML.foto)
            fotoElenco.push({url:prop.@url, didascalia:prop.@didascalia});
        viewFoto(fotoPosition);
        gallery_mc.addChild(fotoLoader);
        manageButton();
    function manageButton():void
        if(fotoPosition<1){
            back_mc.visible=false;
        }else{
            back_mc.visible=true;
        if(fotoPosition>=fotoElenco.length-1){
            fwd_mc.visible=false;
        }else{
            fwd_mc.visible=true;
    function manageFoto(event:MouseEvent):void
        switch(event.currentTarget)
            case fwd_mc:
                if(fotoPosition<fotoElenco.length-1)
                    fotoPosition++;
            break;
            case back_mc:
                if(fotoPosition>0)
                    fotoPosition--;
            break;
        viewFoto(fotoPosition);
    function viewFoto(num:Number):void
        fotoLoader.load(new URLRequest(fotoElenco[num].url));
        fotoLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEventIMG);
        didascalia_txt.text=fotoElenco[num].didascalia;
        manageButton();
    function ioErrorEventIMG(event:IOErrorEvent):void
        manageErrorMessage(true, 1);
    XML code:
    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
        <foto url="img/immagine1.jpg" didascalia="Didascalia 1 foto"/>
        <foto url="img/immagine2.jpg" didascalia="Didascalia 2 foto"/>
        <foto url="img/immagine1.jpg" didascalia="Didascalia 1 foto"/>
        <foto url="img/immagine2.jpg" didascalia="Didascalia 2 foto"/>
    </gallery>

  • Fastest way to load an image into memory

    hi, ive posted before but i was kinda vague and didnt get much of a response so im going into detail this time. im making a java program that is going to contol 2 robots in a soccer competition. ive decided that i want to go all out and use a webcam instead of the usual array of sensors so the first step is to load an image into the memory. (ill work on the webcam once ive got something substanical, lol) since these robots have to be rather small (21cm in diameter) i can only use some pretty crappy processors. the robots are going to be both running gentoo linux on a 600 mhz processor, therefore it is absoleutely vital i have a fast method of loading and analyzing images. i need to be able to both load the image quickly, and more importainly analyze it quickly. ive looked at pixelgrabber which looks good, but ive read several things about javas image handling beging crap. these articles are a few years old, and im therefore wonding if there anything from the JAI that will do this for me. thx in advance.

    well i found out why i was having so much trouble
    installing JAI. im now back on windows and i cant
    stand it, so hopefully the bug will be fixed soon. oIt's not so bad. I mean, that's why we love Java! Once your linux problem is fixed you can just transfer your code there as is.
    well. i like the looks of JAI.create() but im not so
    sure how to use it. at this stage im tying to load an
    image from a file. i no to do this with pixelgrabber
    you use getcodebase(), but i dont know how to do it
    with JAI.create. any advice is appreciated. thx.Here are some example statements for handling a JAI image. There are other ways, I'm sure, but I've no idea which are faster, sorry. But this is quite fast on my machine.
    PlanarImage pi = JAI.create("fileload", imgFilename);
    WritableRaster wr = Raster.createWritableRaster(pi.getSampleModel(), null);
    int width = pi.getWidth(); // in case you need to loop through the image
    int height = pi.getHeight();
    wr = pi.copyData(); // copy data from the planar image to the writable one
    wr.getPixel(w,h,pixel); //  pixel is an int array with three elements.
    int red = pixel[0];     // to find out what's the red component
    int[] otherPixel = {0,0,0}
    wr.setPixel(w,h,otherPixel); // make pixel at location (w,h) black.                And here's a link with sample code using JAI. I've tried several of the programs there and they work.
    https://jaistuff.dev.java.net/

  • How Do I Combine Several Images Into One Image Which Contains Links To A Series Of Web Sites?

    How do I combine several images into one such that the combined image contains a series of web links? In particular, I’d like to create such an image and put it into my Outlook email signature. At present, as per the image below, I have at least six separate images in my email signature with each image containing a web link. Is Photoshop the best tool for this job? Or would it be easier to do this in some other package? I have three packages at my disposal: Photoshop, Ilustrator and Dreamweaver. Can someone please explain in detail how I would do this? Or perhaps someone could direct me to a link that explains how to do this. Thank you.

    Thank you for that correction, Hobotor. I admit I hadn't thought about an image map, in the context of someone who doesn't seem to know HTML very well...  My thinking was running along the use of the Photoshop Slice Tool to get most of the way there...
    To expand on the above, if you were to slice up your image using the Slice Tool, say like this:
    Save for Web & Devices will create the HTML and save all the sub-images.
    Then you edit the HTML and add a (hypertext link) elements surrounding the various images.  Only thing is you'll have to set the border-style of the images to none.
    For example:
    <!-- Save for Web Slices () -->
    <table id="Table_01" width="554" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td colspan="10">
       <img id="Sig_01" style="border-style:none" src="images/Sig_01.jpg" width="554" height="56" alt="" /></td>
    </tr>
    <tr>
      <td colspan="10">
       <a href="http://www.GrahamsWebSite.com"><img id="Sig_02" style="border-style:none" src="images/Sig_02.jpg"
            width="554" height="43" alt="" /></a></td>
    </tr>
    etc.
    A full copy of the HTML and images can be found here...  View Source to see it as an example:
    http://Noel.ProDigitalSoftware.com/temp/Graham/Sig.html
    -Noel

  • How i can load excel sheet into a table in oracle through pl/sql procedure

    Hi,
    How i can load excel sheet into a table in oracle through pl/sql procedure or a pl/sql block. Excel sheet is saved on my c or d drive on my machine. In xls format.

    Depending on how big your spreadsheet is and how frequently you want to do this you might want to contruct insert statements in excel, then run these. I have done this to load a few hundred rows for a one off test on dev.
    e.g. if you have values 1 and 'a' in you spread sheet and want to insert them in to table xxx col1 & 2:
    | /|   A   |   B   |    C
    |1 |col1   |col2   |
    |2 |      1|a      |="insert into xxx ("&$A$1&","&B1&") values ("&A2&",'"&B2&"');"then paste the contents of colum C
    insert into xxx (col1,col2) values (1,'a');into sqlplus or a script.

  • How do i bring an image into photoshop?

    how do i bring an image into photoshop?

    Additionally, if you've copied an image from a website or other location, you can go to File > New and, for CS6, at least, the canvas will already be the dimensions of the image you have in your clipboard. So, once you start that new file, you can simply go to Edit > Paste (or hit cmd V) to drop in the image.
    Please let us know if we can assist you any further.

  • I cannot seem to load raw images into LR 2.5.  I've been using this for years.  I always load from memory card, but it gives me an unknown error message.  I tried to load from camera, hard drive, & external drive and still will not work.  I checked import

    I cannot seem to load raw images into LR 2.5.  I've been using this for years.  I always load from memory card, but it gives me an unknown error message.  I tried to load from camera, hard drive, & external drive and still will not work.  I checked import menu and nothing has changed.  I loaded the photos onto my tablet and images are fine, so do not feel it is the memory card.  Any thoughts?

    The error message probably said "unsupported or damaged"
    The T3 requires Lightroom 3.4.1 or later. You can either upgrade to a more current version of Lightroom (version 5.6 is the most recent) or you can use the free Adobe DNG Converter to convert the RAWs to DNG, which should import into Lightroom properly.

  • How do you set an image into the background of a JPanel or JFrame?

    How do you set an image into the background of a JPanel or JFrame?

    Something like this, Ive thrown in an ImageIcon on a
    button too for good measure.
    import java.awt.*;
    import javax.swing.*;
    public class JFrameImage extends JFrame {
    public JFrameImage() {
    Container c    = getContentPane();
    JPanel panel = new JPanel(){
                 public void paintComponent(Graphics g)     {
    ImageIcon img = new
    = new ImageIcon("background.jpg");
                      g.drawImage(img.getImage(), 0, 0, null);
                      super.paintComponent(g);
            panel.setOpaque(false);
    ImageIcon icon = new ImageIcon("onButton.jpg");
    JButton button = new JButton(icon);
    panel.add(button);
    c.add(panel);
    public static void main(String[] args) {
    JFrameImage frame = new JFrameImage();
    frame.setSize(200,200);
    frame.setVisible(true);
    Going totally fancy pants
    ImageIcon bigImage = new ImageIcon(bgImage.getImage().getScaledInstance(getWidth(), getHeight(),Image.SCALE_REPLICATE));
    g.drawImage(bigImage.getImage(), 0, 0, this); Will scale the image to the size of the panel
    whereas
    for (int y = 0; y  < getHeight(); y = y + image.getHeight(null))
    for (int x = 0; x< getWidth(); x = x + image.getWidth(null))
    g.drawImage(image, x, y, this); Will give a tiled effect
    Try tiling with an animated gif and bring your processor to a standstill.

Maybe you are looking for