Search Results

Search found 1 results on 1 pages for 'elvencode'.

Page 1/1 | 1 

  • Have something loaded only when JList item is visibile

    - by elvencode
    Hello, i'm implementing a Jlist populated with a lot of elements. Each element corresponds to a image so i'd like to show a resized preview of them inside each row of the list. I've implemented a custom ImageCellRenderer extending the Jlabel and on getListCellRendererComponent i create the thumbnail if there'snt any for that element. Each row corresponds to a Page class where i store the path of the image and the icon applied to the JLabel. Each Page object is put inside a DefaultListModel to populate the JList. The render code is something like this: public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Page page = (Page) value; if (page.getImgIcon() == null) { System.out.println(String.format("Creating thumbnail of %s", page.getImgFilename())); ImageIcon icon = new ImageIcon(page.getImgFilename()); int thumb_width = icon.getIconWidth() > icon.getIconHeight() ? 128 : ((icon.getIconWidth() * 128) / icon.getIconHeight()); int thumb_height = icon.getIconHeight() > icon.getIconWidth() ? 128 : ((icon.getIconHeight() * 128) / icon.getIconWidth()); icon.setImage(getScaledImage(icon.getImage(), thumb_width, thumb_height)); page.setImgIcon(icon); } setIcon(page.getImgIcon()); } I was thinking that only a certain item is visibile in the List the cell renderer is called but i'm seeing that all the thumnails are created when i add the Page object to the list model. I've tried to load the items and after set the model in the JList or set the model first and after starting appending the items but the results are the same. Is there any way to load the data only when necessary or do i need to create a custom control like a JScrollPanel with stacked items inside where i check myself the visibility of each elements? Thanks

    Read the article

1