Can't understand why my DefaultListCellRenderer doesn't work

Hello i know that from the subject title it seems that this is the wrong category to post but because i need to load thumbnails in list and i resize them i didn't know where to post sorry if it is the wrong plase and also sorry for my bad english.
I am making a programm that get's from the user some image paths , then makes thumbnails and then shows the thumbnails with a status and the name of the image. My list has HORIZONTAL_WRAP layout orientation and because i want to show the name the status and the thumbnail in the list i made a DefaultListCellRenderer. The problem is that when i add elements in the list it appears nothing but when i press with the mouse somewhere int the list the listImagesValueChanged is invoked and the data are passed correctly. I made an class named ImageThubInfo to save the name and the thumbnail for eatch image, also i am using a swing worker to create the thubnails and pass them along with all other information in ImageThubInfo and then store all ImageThubInfo objects to a list. When the worker thread is done it tries to add those elements to the list here is my code
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
* ImageThubInfo stores information for each image
* @author maxsap
public class ImageThubInfo  {
    public ImageThubInfo() {
    public ImageThubInfo(String status, String name, int width, int height, long size) {
        this(status, name, width, height, size, null);
    public ImageThubInfo(String status, String name, int width, int height, long size,BufferedImage thumbnail) {
        this.status = status;
        setName(name);
        this.width = width;
        this.height = height;
        this.size = size;
        this.thumbnail = thumbnail;
    public void setStatus(String status) {
        this.status = status;
    public String getStatus() {
        return status;
    public void setName(String name) {
        int indexOf = name.indexOf(".");
        this.name = name.substring(0, indexOf);
        JOptionPane.showMessageDialog(null, this.name);
    public String getName() {
        return name;
    public void setWidth(int width) {
        this.width = width;
    public int getWidth() {
        return width;
    public void setHeight(int heigth) {
        this.height = height;
    public int getHeight() {
        return height;
    public void setSize(long size) {
        this.size = size;
    public float getSize() {
        return size;
    public void setThumbnail(ImageIcon BufferedImage) {
        this.thumbnail = thumbnail;
    public BufferedImage getThumbnail() {
        return thumbnail;
    private String status;
    private String name;
    private int width;
    private int height;
    private long size;
    private BufferedImage thumbnail;
}this is my DefaultListCellRenderer class
import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JList;
* @author maxsap
public class ImageThubInfoRenderer extends DefaultListCellRenderer {
    public ImageThubInfoRenderer(){}
      @Override
    public Component getListCellRendererComponent(JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {
         super.getListCellRendererComponent(list,value,index,isSelected,
                                                            cellHasFocus);
        ImageThubInfo info = (ImageThubInfo) value;
        String name = info.getName();
        String state = info.getStatus();
        BufferedImage thumbnail = (BufferedImage)info.getThumbnail();
        setIcon(new ImageIcon(thumbnail));
        setText(name+" Current State: "+state);
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        return this;
}and this is my swing worker class
public class ThumbLoader extends SwingWorker<List<ImageThubInfo>, BufferedImage> {
      private DefaultListModel model;
      private int total;
      private File [] files;
      private List<ImageThubInfo> imageList;
      protected ThumbLoader(DefaultListModel model,File []files){
            this.model = model;
            this.files= files;
      @Override
      protected List<ImageThubInfo> doInBackground() throws Exception {
            imageList = new LinkedList<ImageThubInfo>();
             for (int i = 0; i < files.length; i++) {
                ImageIcon icon;
                icon = createImageIcon(files.toString());
if(icon != null){
ImageIcon thumbnailIcon = new ImageIcon(getScaledImage(icon.getImage(), 100, 100,files[i]));
return imageList;
protected ImageIcon createImageIcon(String path) {
if (path != null) {
return new ImageIcon(path);
} else {
System.err.println("Couldn't find file: " + path);
return null;
private Image getScaledImage(Image srcImg, int w, int h, File file){
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = resizedImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(srcImg, 0, 0, w, h, null);
ImageThubInfo tubInfo = new ImageThubInfo("Waiting",file.getName(),srcImg.getHeight(null),srcImg.getHeight(null),300,resizedImg);
imageList.add(tubInfo);
JOptionPane.showMessageDialog(null, new ImageIcon(resizedImg));
g2.dispose();
return resizedImg;
}protected void done() {
setProgress(100);
try {
//JOptionPane.showMessageDialog(null, imageList.size());
List<ImageThubInfo> imageList = this.get();
for(int i=0; i< imageList.size(); i++){
JOptionPane.showMessageDialog(null, new ImageIcon(imageList.get(i).getThumbnail()));
model.addElement(imageList.get(i));
} catch (InterruptedException ex) {
Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionException ex) {
Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "DONE");
}}can anyone tell me what i am doing wrong???? please help because i really can't understand what i am doing wrong.
thenks in advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Works okay now. Many changes to ThumbLoader:
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.concurrent.*;
import java.util.logging.*;
import java.util.List;
import java.util.LinkedList;
import javax.swing.DefaultListCellRenderer;
import javax.swing.*;
public class ThumbLoader extends SwingWorker<List<ImageThubInfo>, Void> {
    private DefaultListModel model;
    private int total;
    private File[] files;
    private List<ImageThubInfo> imageList;
    protected ThumbLoader(DefaultListModel model, File[] files){
        this.model = model;
        this.files = files;
    @Override
    protected List<ImageThubInfo> doInBackground() throws Exception {
        imageList = new LinkedList<ImageThubInfo>();
        for (int i = 0; i < files.length; i++) {
            BufferedImage image = null;
            try {
                image = javax.imageio.ImageIO.read(files);
} catch(IOException e) {
System.out.println("read error for " + files[i].getPath() +
": " + e.getMessage());
if(image != null){
BufferedImage scaled = getScaledImage(image, 100, 100);
ImageThubInfo tubInfo = new ImageThubInfo("Waiting",
files[i].getName(),
image.getHeight(),
image.getHeight(),
300, scaled);
imageList.add(tubInfo);
return imageList;
private BufferedImage getScaledImage(BufferedImage srcImg, int w, int h){
BufferedImage resizedImg = new BufferedImage(w, h,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = resizedImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2.drawImage(srcImg, 0, 0, w, h, null);
g2.dispose();
// JOptionPane.showMessageDialog(null, new ImageIcon(resizedImg));
return resizedImg;
protected void done() {
setProgress(100);
try {
//JOptionPane.showMessageDialog(null, imageList.size());
// List<ImageThubInfo> imageList = this.get();
imageList = get();
for(int i=0; i< imageList.size(); i++){
// JOptionPane.showMessageDialog(null, new ImageIcon(
// imageList.get(i).getThumbnail()));
model.addElement(imageList.get(i));
} catch (InterruptedException ex) {
// Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE,
// null, ex);
System.out.println("InterruptedException: " + ex.getMessage());
} catch (ExecutionException ex) {
// Logger.getLogger(ThumbLoader.class.getName()).log(Level.SEVERE,
// null, ex);
System.out.println("ExecutionException: " + ex.getMessage());
// JOptionPane.showMessageDialog(null, "DONE");
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
public class Test {
    private JScrollPane getContent() {
        File[] files = getFiles();
        DefaultListModel model = new DefaultListModel();
        JList list = new JList(model);
        list.setCellRenderer(new ImageThubInfoRenderer());
        SwingWorker worker = new ThumbLoader(model, files);
        worker.execute();
        return new JScrollPane(list);
    private File[] getFiles() {
        String prefix = "images/geek/geek";
        String[] ids = { "-c---", "--g--", "---h-", "----t" };
        String ext = ".gif";
        File[] files = new File[ids.length];
        for(int i = 0; i < ids.length; i++) {
            String path = prefix + ids[i] + ext;
            URL url = getClass().getResource(path);
            try {
                files[i] = new File(url.toURI());
            } catch(URISyntaxException e) {
                System.out.println("everything is busted!");
        return files;
    public static void main(String[] args) {
        Test test = new Test();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(test.getContent());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}geek images from [Geek Images|http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html]

Similar Messages

  • HT1695 Hey, guys! I connected to the wi-fi by my iPhone (5) for 3 weeks. Now my iPhone doesn't connect to the network anymore. And I can't understand why. Will you please help me? It's strange,cause tonight I connected frequently. But now I can't! :(

    Hey, guys! I connected to the wi-fi by my iPhone (5) for 3 weeks. Now my iPhone doesn't connect to the network anymore. And I can't understand why. Will you please help me? It's strange,cause tonight I connected frequently. But now I can't! :(

    Hello LNIN5,
    Thank you for using Apple Support Communities!
    I have a couple resources for you to help troubleshooting wifi connection issues with an iOS device.
    The first is named iOS: Troubleshooting Wi-Fi networks and connections and can be found here http://support.apple.com/kb/ts1398.
    Take care,
    Sterling

  • HT3529 Can someone help me understand why my iMessage no longer works on my iPad

    Can someone help me understand why my iMessage no longer works on my iPad

    iOS: Troubleshooting Messages
    iOS: Troubleshooting FaceTime and iMessage activation

  • After updating software on my Apple TV it is asking to connect to iTunes. Can't understand why?

    After updating software on my Apple TV it is asking to connect to iTunes. Can't understand why?

    You can try borrowing one. These cables are common for Android, Kindle etc. users.
    Here are some steps and notes to try:
    MANY people are reporting they've had to try multiple micro USB cables to find one that works. I got one that worked from a neighbor.
    For clarification, this needs to be a "micro" USB, not a "mini" USB
    Some people have also reported they've had to try the Restore process more than once.
    1. Unplug Apple TV and move it to your computer running latest version of iTunes.
    2. Quit iTunes if running.
    3. Plug micro USB cable to the back of the Apple TV.
    4. Power the Apple TV using  the AC cable.
    5. iTunes shoud either launch itself (a good indication that the micro USB cable you're using is compatible), or launch iTunes.
    6. Click Restore. Software will download and install (big file).

  • Hi , please tell me why my ipod doesn't work ... when i conect it to my pc nothing happen .. and i can turn on my ipod .. why ? please help me

    hi , please tell me why my ipod doesn't work ... when i conect it to my pc nothing happen .. and i can turn on my ipod .. why ? please help me

    Go to
    http://bt.custhelp.com/app/answers/detail/a_id/47531
    and follow the instructions
    This was put up by BT several months ago as part of the advance notification that the Yahoo service through them was closing

  • Can someone help me understand why my i tunes stop working after my library comes up?

    Can someone please help me understand why my i tunes stop working after my library comes up?

    Hello generousdragon,
    It sounds like you are unable to use iTunes shortly after launching it. Use the following article to help troubleshoot the issue, named:
    iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues
    http://support.apple.com/kb/ts1717
    Start with this step to isolate 3rd party plugins that may be causing an issue, an use the rest of the troubleshooting if needed.
    Start iTunes in Safe Mode
    Open iTunes in Safe Mode to isolate any interference from plug-ins or scripts not manufactured by Apple.
    Hold down Shift–Control while opening iTunes. You should see a dialog that says "iTunes is running in safe mode" before iTunes finishes starting up.
    Click Continue.
    See if the issue you're experiencing persists in Safe Mode.
    If you have the same issue while iTunes is in Safe Mode, proceed to the "Create a new user account" section. If you don't experience the same issue, follow these steps to remove third-party plug-ins.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Hi there, i have a ipod nano general 7, just used one year. Now can't charge battery. When charging, the icon shows full power, but disconnect it. It becomes dark, no power. Why, the battery doesn't work ?

    I've a ipod nano general 7, I've just used it one year. Now, I can't charge the battery. When charging, the icon shows full power. But when I disconnect, the ipod becomes dark, no power is keeped. Why, the battery doesn't work ? the life of my ipod's battery is too short ? 

    Howdy tamsg,
    Welcome to Apple Support Communities.
    The article linked below provides a lot of great troubleshooting tips that can help you resolve the issue with your iPod nano charging or displaying a blank black screen.
    iPod nano (7th generation): Hardware troubleshooting - Apple Support
    So long,
    -Jason

  • How to use documentbeforesaved method? And why my code doesn't work in template files?

    Can someone help me with these two codes?
    ----Beginning of code 1-------------
    Private WithEvents App As Word.Application
    Private Sub Document_Open()
    Set App = Word.Application
    End Sub
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox("BeforeSave")
    End Sub
    --------------End of the code----------------
    Beginning of code 2--------------- Code 2 is from https://msdn.microsoft.com/en-us/library/office/ff838299(v=office.15).aspx
    Public WithEvents appWord as Word.Application 
    Private Sub appWord_DocumentBeforeSave _ 
     (ByVal Doc As Document, _ 
     SaveAsUI As Boolean, _ 
     Cancel As Boolean) 
     Dim intResponse As Integer 
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox("BeforeSave")
    End Sub
    In the first code, they have:
    Private Sub Document_Open()
    Set App = Word.Application
    End Sub
     I test these two codes in "This document" object, and I find out the first code works but the second code are not!
    Why second code doesn't work?
    Extra question: I am using microsoft 2013. I insert this code into a macro-enabled template. But when I am about to save my file I am expecting these code works. However, they didn't work!
    Thank you for solving these problem for me!

    Hello,
    Please note that the code snippet 2 in your post is different from the code snippet in the MSDN document. Also please read the comments of the MSDN code sample:
    This example prompts the user for a   yes or no response before saving any document.
    This code must be placed in a   class module, and an instance of the class must be correctly initialized to   see this example work; see
    Using Events with the Application Object for   directions on how to accomplish this.
    Public WithEvents appWord   as Word.Application
    Private Sub   appWord_DocumentBeforeSave _
     (ByVal Doc As Document, _
     SaveAsUI As Boolean, _
     Cancel As Boolean)
     Dim intResponse As Integer
     intResponse = MsgBox("Do you really   want to " _
     & "save the document?", _
     vbYesNo)
     If intResponse = vbNo Then Cancel = True
    End Sub
    So the problem in your code snippet 2 is that you didn't put it into a class module and initialize the class module. If you just put it into ThisDocument, you have to initialize the word application object.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Why the preloader doesn't work in IE 8 but works in FireFox?

    Why the preloader doesn't work in IE 8 but works in FireFox?
    Please see the attached files.  Thanks in advance.

    Why doesn't the preloader work in IE8?
    What's "virtual sandbox"?

  • Why the imsg doesn't work without a sim card with iOS 7???

    Why the imsg doesn't work without a sim card with iOS 7???

    If it worked for you using iOS 6, then it appears iOS 7 has made some changes.  Was it working before?

  • I can't understand why I haven't sold any items in my eBay store except for books in several months.

    In Spring 2014 approx., I began adding my collection of books to my eBay store.  I was on ABE Books but they were very expensive, and my books on eBay started selling almost right away.  Unforunately they are all around $4 give or take, and with only 3 or 4 selling per month, it doesn't recoup the fee I pay for my eBay Store. I don't understand why I have had almost no sales in any of my other product areas, once I put my books for sale on eBay.  There isn't some sort of thing that blocks out my other items now that I have books listed, is there? I have to get some sales in my clothing, shoes, handbags and designer goods sections otherwise I'll have to go back to just a basic eBay store.  I can't live on sales of only 4 books at $4 each month.

    Now ill and disabled, I want to sell everything to benefit animal rescue before it is too late I noticed these claims in your Store header. While BDR (Buyers Don't Read), I would like to encourage you to drop both. Customers don't care about our personal lives. They want to buy stuff at a good price. Self-pity, no matter how true, will turn off buyers because there are way too many scammers using the same kind of tale of woe. Rethink and rewrite it. You don't owe anyone an explanation of why you are selling your New With Tags*  goods.  And you can't advertise that you are supporting a charity without clearing it with eBay first. This could lead to having all your items closed. Again, this is because scammers have done the same thing. Here's the policy:http://ocsnext.ebay.ca/ocs/sc  I seem to remember you from postings a few years ago. I hope your life has gotten better since then. You were in some distress as I recall.  BTW- Your post encouraged me to clean up the 'aisles' in my Store. I was finding some pretty odd locations-- why would I have put a Vogue dress pattern in my 'Erotica, Sex and Sexuality' aisle, for example? Late night posting probably.   So thank you!     *NWT is a common Search. You use 'Tags On' which is not searched.

  • HT4623 it is telling me that my apple ID is disabled and I can't understand why, any suggestions?

    I am unable to update my apps because I got a message that says my apple ID is disabled however it has not changed.  I can't understand what else I can do to corrrect this, Please advise
    Thank you

    Why do I see the message "This Apple ID has been disabled for security reasons” when I enter my password?
    This message means that someone was unable to sign in to this account multiple times. The Apple ID system will disable the account to prevent unauthorized people from gaining access to your information. You'll need to follow the instructions on My Apple ID to reset your password.
    If that does not work then contact iTunes as the other replier said

  • Why this example doesn't work ?

    for example below:
    html code:
    <applet code=LunarPhasesRB.class width="200" height="200">
        </applet>when i run it on IE , i get below result:
    failed to loading java program.
    why it doesn't work on IE ?
    who can help me ?
    thanks !

    thanks a lot!
    left of web browser appear below info:
    small application program LunarPhasesRB notinited
    what does it mean ?
    if i click "Click to activate and use this control".
    another err:
    failed to loading java program.
    who can help me ?

  • Why FileUtils::CopyFile doesn't work with blank space?

    Hi all,
    If I have a destination directory with blank space inside, looks like: "C:\Users\Pattrick James\Documents" for Windows or "Macintosh HD:Users:Pattrick James:Documents" for Mac.
    Then I want to copy a file to that directory, use FileUtils::CopyFile(src, des). Why it doesn't work?
    Can someone please help me to resolve this issue without change my path?

    Sorry, it works fine. It happens because the permission of the directory.

  • Why Detect Displays doesn't work anymore?

    I use my PB to watch movies using my TV and the S-Video to RCA cable, but since the last upgrade 10.4.6 the Detect Displays option (in display menu bar AND preference pane) doesn't work.
    The TV shows a dimmed image of what's suppose to show and sometimes it appears vertically distorted.
    I disconnected the S-Video cable and restarted the PB but it still shows that "something" is connected to the s-video port.
    Which files should I delete to "reset" video preferences?
    UPDATE: PRAM reset didn't work...
    Thanks in advance

    Well, the cable can't be the problem, because the computer is "stuck" with a two monitor configuration, even without the cable plugged in, that's why im guessing there's some kind of switch (i hope) that i can reset so the mother board stops thinking i have another display plugged.... the second problem is that if i plug the s-video to rca cable (that came with the laptop) i can't get a clear tv signal from it... it's distorted.... i'll probably open up the computer and check the s-video port... wish me luck.

Maybe you are looking for