How to update drawImage() images

This may be quite simple for most, but I'm stumped. I have BuffereredImages[] being passed to a class where my Graphics are. I then use drawImage() to draw the images on the JPanel. That all works fine. My problem is that I have a button that I need to repaint or redraw the images when the button is clicked. I have the button listener all setup. I just don't know how to get the drawImages() to redraw using different images.
In my main panel I have:
         die1 = rand.nextInt(6);
         die2 = rand.nextInt(6) + 6;
         //get images for vending machine
            img = loadImages();
         //paint all images
            dieImg = new DiceImage(die1, die2, img);Then my button listener:
       private class ButtonListener implements ActionListener
         //declare variables 
         private Object source;
          public void actionPerformed(ActionEvent event)
            source = event.getSource();
            *   Roll Button         *
            if (source == rollBtn)
              //paint all images
            *   Pass Button         *
            if (source == passBtn)
     System.out.println("Pass");
      } //end of Button Listener ClassThen this is where I get the images:
       private BufferedImage[] loadImages()
           //create prefix for path if needed
         String prefix = "";
           //create array of filenames to draw
         String[] fileNames = { "die1-1.gif", "die1-2.gif", "die1-3.gif", "die1-4.gif", "die1-5.gif", "die1-6.gif",
                                "die2-1.gif", "die2-2.gif", "die2-3.gif", "die2-4.gif", "die2-5.gif", "die2-6.gif" };
         //get the files
         BufferedImage[] images = new BufferedImage[fileNames.length];
         for(int j = 0; j < images.length; j++)
            try
               URL url = getClass().getResource(prefix + fileNames[j]);
               images[j] = ImageIO.read(url);
                catch(MalformedURLException mue)
                  System.err.println("url: " + mue.getMessage());
                catch(IOException ioe)
                  System.err.println("read: " + ioe.getMessage());
           //return the array of images
         return images;
      }And this is where I draw the images:
       public class DiceImage extends JPanel
         private int x, y;
         private int width = 500, height = 150;
         private BufferedImage[] image;
         private int die1, die2;
      //create constructor and pass in image array     
          public DiceImage (int die1, int die2, BufferedImage[] image)
     this.die1 = die1;
     this.die2 = die2;
                     this.image = image;
      * Beginning of the paintWindow method
          public void paint(Graphics display)
     super.paint(display);
     //draw images in vending machine 3D box
                      x = 75;  //center the to images evenly
                      y = 10;  //10 pixels down from the top of the panel
     display.drawImage(image[die1], x, y, this);
     display.drawImage(image[die2], x + 200, y, this);                                   
         } // end paint
      //sets the preferred size for the item box
          public Dimension getPreferredSize()
            return(new Dimension(width, height));
      } //end of class   Let me know if you need any other snippets of code. I'm new to Java so please be gentle!

I just don't know how to get the drawImages() to redraw using different images.display.drawImage(image[die1], x, y, this);
display.drawImage(image[die2], x + 200, y, this);     
In your paint method you are specifying the image to be drawn based on the values of die1 and die2. So if you want to draw a different image then you need to change the value of these two variables. So you need a method that changes these values.

Similar Messages

  • How to update an image file into existing file

    how to update an image file into existing file

    Hi,
    So, i assume you want to change one picture. On Stage, i have edgeAnimate (an image), and
    1) i am using the div tag.
    So: sym.$("edgeAnimate").css("background-image", "url(images/myImage.png)" ); will change my picture.
    Link: CSS properties.
    More CSS:
    sym.$("edgeAnimate").css( { "background-image": "url(images/myImage.png)", "background-size": "100% 100%", "background-repeat": "no-repeat", "cursor": "pointer" } );
    Using a path variable:
    var myPath = "images/myImage.png";
    sym.$("edgeAnimate").css( { "background-image": "url("+myPath+")", "background-size":"100% 100%", "background-repeat":"no-repeat", "cursor": "pointer" } );
    2) i am using the img tag.
    I can add a class using Edge Animate user interface.
    I choose one class name: "newImage".
    So:  sym.$(".newImage").css("background-image", "url(images/myImage.png)" ); will change my picture.
    Note: I assumed you don’t need to preload your picture.

  • Reg How to Update DeleteFlag Image (Default N)  Value in Table

    Hi Friends,
    I have One Column Delete Button(Style Image) in Advanced Table So Based on That Delete Button Click I need to Update Value in Table(DeleteFlag =Y )
    So How to Update Value in Table(Data Base).
    Select empno,deleteflag from Emp where empno=:1
    I attached this EmpVO to Advance Table So How to update Delete Flag(Y) Value.
    Hint:::::: Iam Using Packages(Pl Sql) And Read Only VO's Only.
    With out Using Package & EOVO Update is Possible In OAF.
    Thanks & Regards
    San

    Okay ,
    Here we go ,
    Step 1 : Select the item in the table ( image) and go to property inspector and select fire action , give some name for Action .
    Step 2 : Capture the above event from your controller class ( ProcessFormRequest () ) and Implement SQL statement
    Use below code :
    Import the followings
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    if ("YourEventID".equals(pageContext.getParameter(EVENT_PARAM))) // replace your event id created above
    Inside if statement Add code to handle sql statement .
    try
    String Query = " "; // write any single SQL statement along with bind parameter inside " " , in your case it should be update statement
    PreparedStatement stmt = conn.prepareStatement(Query);
    stmt.setString(1,Paramtervalue); //set your bind parameter value here ( where clause paramter )
    catch(Exception exception)
    throw new OAException("Error in Staffing Query"+exception, OAException.ERROR);
    Keerthi
    Edited by: keerthioaf on Nov 27, 2012 1:47 AM

  • How to update a image via URL SWF

    Hi, I want to make a sort of slideshow of the players in my game (In game when you change clothes/weapons the image auto updates to show your current character) How would I insert images into CS4 and when the image updates for it to update in CS4? PS. This is when the project is exported and uploaded to my website. Example image that auto updates:
    (http://www.msblur.com/GD/?n=AdminLee) = (http://www.msblur.com/GD/?n=CHARACTERNAME) Where CHARACTERNAME is thats where I put each individual character I want to add in..Thanks.

    you can load image files into your swf dynamically but you can't easily change swf library items dynamically.
    how you use php depends on whether you're using as2 (use loadvars) or as3 (use the urlloader class).  how you use html depends on your actionscript version and what you're trying to do.  if you want to open a html page in a browser window use getURL (as2) or navigateToURL (as3).

  • Posts going missing - How to update an image once it has been displayed

    Something is very wrong with my posts here. I made this post earlier today, and added it to my watch list. The last time I checked it, there were no replies. Now the title in my watch list has been changed to null and the post is not showing up in the forum. Grrrr.
    Anyway, onto the main event.
    I've got some code that, among other things, displays an image in a Frame. I'm doing this by subclassing JLabel and overriding the paintComponent method.
    My question though, is how can I load a different image in place of that one ? I'm trying to run a slideshow, and whenever I load another image, I can see the new object is being created (I have a println in there), but the image in the frame is not updated with the new one.
    Here is my overridden paintComponent method:
    protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.clearRect(0, 0, w, h);
              g.setColor(Color.BLACK);
         Graphics2D g2d = (Graphics2D)g.create();
         g2d.drawRenderedImage(image,null);
              g2d.dispose(); //clean up
    Can anyone advise how I would get the picture in the frame to update ?

    If you are looking up onto staged data, just snapshot the data once a day.
    Or you could just do an External Lookup, where there is no need to refresh the data as you can just look it up dynamically.
    You will not get any 'fuzziness' with this approach.

  • How to update previously modified Image and prevent from reverting?

    Below is my code for updating a painComponent:- it basically zooms in on a particular image. The zooming works for the first try. But since the Image ITSELF isnt updated if i try to zoom in on the zoomed image its actually trying to zoom the original image since my g.drawImage() has the original Image (not zoomed). Is there anyway to update the Image so that it is the previously zoomed image and not the original? I searched for "zoom" throughout the boards and no one seemed to brough this "problem" up. Can someone help me out? thanks
    public void paintComponent(Graphics g) {
    g.drawImage(zoomingImage,0,0,(int)zoomFrame.getWidth(),(int)zoomFrame.getHeight(),((Point) zoomStartPoints.lastElement()).x,((Point) zoomStartPoints.lastElement()).y,((Point)zoomEndPoints.lastElement()).x,((Point) zoomEndPoints.lastElement()).y,Color.WHITE,null);}
    setOpaque( false ); // background will not be painted by super.paintComponent()
    if (startPoint != null && endPoint != null) {
    int x = Math.min(startPoint.x, endPoint.x);
    int y = Math.min(startPoint.y, endPoint.y);
    int width = Math.abs(endPoint.x - startPoint.x);
    int height = Math.abs(endPoint.y - startPoint.y);
    g.drawRect(x, y, width, height);
    if (dragged ) {
    g.drawImage(zoomingImage,0,0,(int)zoomFrame.getWidth(),(int)zoomFrame.getHeight(),((Point) zoomStartPoints.lastElement()).x,((Point) zoomStartPoints.lastElement()).y,((Point) zoomEndPoints.lastElement()).x,((Point) zoomEndPoints.lastElement()).y,Color.WHITE,null);
    dragged = false;
    super.paintComponent(g); }

    http://feeds.feedburner.com/
    http://feeds.feedburner.com/scottwimberly/JDaY is my URL to see what I have done.

  • How to update image with data from database?

    hi,
    is it possible to update an image object which serves as template with some data from a database table like user name etc. by converting it to image bytes and how? The final image would show user name as part of the image

    anybody?

  • How do you update the image used for your podcast?

    I just recently updated the logo for my podcast and want to know how to alter the one shown on iTunes. I use hipcast to host my podcasts and it tends to update my info on iTunes when I change it via hipcast but does not seem to be working for my pic.

    Make the new image - it should be 1400 x 1400 px - and make sure to give it a different file name from the existing image, or the iTunes Store, which caches the image, won't know it's been changed.
    Upload it to your server and change the URL in the feed, or make the change by whatever method you used to enter the original in Hipcast.
    It's likely to take the iTunes Store quite some days to update the image, so don't panic if it doesn't update at once.

  • How to update WinPE Boot image

    Currently using WinPE 3.0 Version A10.
    As face some new model laptop fail to run WinPE.
    After i update WinPE3.0 Version A12.
    How to update the boot image?
    Please help.
    Whelen

    Are you using MDT or just WinPE alone?
    If you are using MDT, you can add the driver into the "Out of Box" driver category, and then perform an update of the Deployment Share.
    Keith Garner - keithga.wordpress.com

  • How can I update my image in a loop?

    I want to use "paint( )" automaticlly to display my 3D image slice by slice. I can't understand why it only display my final slice. Below is my coeds:
    // press butten to display my 3D image slice by slice
    if(e.getActionCommand() == "Play")
         for(int i = 0; i < finalSlice; i++)
              if(presentSlice == finalSlice)
                   presentSlice = 0;
              presentSlice = presentSlice + 1;
              // read a new slice from a 3D data. Return
              // matrix is a new 2D image data
              pixel = mccd.readSlice(presentSlice, mapModel);
              //Gererate a new slice image
              img = createImage(new MemoryImageSource(width, height, pixel, 0, width));
              //input the image onto my image panel;
              imgPanel.imageUpdate(img);
              } // Here can not work. Only can               // work in the last time of loop.
    public class ImagePanel extends JPanel
         public void imageUpdate(Image image)
              this.image = image;
              repaint();
         public void paintComponent(Graphics g)
              super.paintComponent(g); //paint background
              //Draw image at its natural size first.
              g.drawImage(image, 0, 0, this);
    Thanks a lot for any help. Could you email me on
    [email protected] Thanks again

    You can try the following:
    Create a new object that extends runnable. Have a variable that keeps track of the current slice. In its paint() method, paint the current slice.
    Now, in its run() method start from the first slice and get into a loop that calls Thread.sleep(1000) and then makes the current slice = to the next slice. you can replace 1000 with whatever duration you want.
    My recommendation is that this object should extend a container. After that, you just add the component into a window and display it.
    Hope this helps,
    Calin
    PS: I did this and it worked for me. If you need it I will try to give you some code you can start from.

  • How to update/refresh main panel's image displays inside subvi?

    Hi everyone,
    I have a image display control located in my main panel,  and I have a subvi which do some process works inside it.
    but what I have done inside the subvi can not be seen in the main panel.
    I used image session controls as the input/outpout nodes for subvi.
    If I use image display control as input node for subvi,
    I can see the realtime displays in the subvi's panel,
    but this is not waht I wanted.
    anyone have good idea?
    Solved!
    Go to Solution.

    Reall sorry, i have attached 8.6 version.
    Also, I think the answer of Andrey_Dmitriev is what you are looking for. I think I understand your problem now. My example updates the image only after subVI is executed.
    Regards,
    https://decibel.ni.com/content/blogs/kl3m3n
    "Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
    Attachments:
    mainVI_1.vi ‏36 KB
    mainVI_2.vi ‏36 KB
    subVI_sobel.vi ‏9 KB

  • How to update images?

    I need to update several images from the DAM and it be updated where they are referenced.

    when you upload new image with same name it overites & no need to update the referenced places.   Note with these you will loose all the version.   What is your exact usecase

  • How-To update Newsstand Default Cover Image

    We would like to update the app cover art image that appears in the iTunes App Store to match the current issue of our publication.
    In the past I have been able to do this in ITC without uploading a new app binary or creating a new app version, just by editing the Newsstand default cover image in the app's version information screen on ITC.
    This functionality is also mentioned in the Adobe DPS documentation:
    "The image you specify in the Newsstand section appears in the Apple App Store and the iTunes Store. Whenever you publish a new folio, you can upload a new image in the Newsstand section of iTunes Connect to update your app’s appearance in the App Store and in iTunes." - Adobe iOS Publishing Companion Guide (Professional Edition)
    ITC was recently updated with a new UI, and now it does not seem to be possible to update our cover image. I am not able to remove the current cover art or upload new cover art.
    Is anyone else having trouble with this? Is it now necessary to upload a new app binary in order to change the cover art image in the App Store?

    I made a mistake and selected the wrong image when I
    initiated the podcast and have updated the image on
    my feed, however it hasn't updated on iTunes. Will
    it correct itself or is there a way to refresh/update
    the image?
    I have the same issue. Did it ever self correct? I also have never had the more recent episodes show up since the initial feed post.
    thx.dtw
    g5   Mac OS X (10.4.9)  

  • How to view the image by using mousedrag event?

    How can i move the full image by using mousedrag event(not using scrollBar and the frame should not reziable).
    e.g
    click the mouse in image and drag right side or towards down,the image should move to till the end in width or height
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class LoadAndShow extends JPanel implements MouseMotionListener{
        BufferedImage image;
        Dimension size = new Dimension();
        public LoadAndShow(BufferedImage image) {
            this.image = image;
            size.setSize(image.getWidth(), image.getHeight());
         * Drawing an image can allow for more
         * flexibility in processing/editing.
        protected void paintComponent(Graphics g) {
            // Center image in this component.
            int x = (getWidth() - size.width)/2;
            int y = (getHeight() - size.height)/2;
            g.drawImage(image, x, y, this);
        public Dimension getPreferredSize() { return size; }
        public static void main(String[] args) throws IOException {
             //set the image path
            String path = "Images/dinette.jpg";
            BufferedImage image = ImageIO.read(new File(path));
            LoadAndShow test = new LoadAndShow(image);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setResizable(false);
            f.add(test);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
            //showIcon(image);
         * Easy way to show an image: load it into a JLabel
         * and add the label to a container in your gui.
        private static void showIcon(BufferedImage image) {
            ImageIcon icon = new ImageIcon(image);
         public void mouseDragged(MouseEvent arg0)
              // TODO drag the image
         public void mouseMoved(MouseEvent arg0)
    }

    Following is the updated code for image move on mouse move.
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.awt.event.MouseListener; public class LoadAndShow extends JPanel implements MouseMotionListener,MouseListener{
    BufferedImage image;
    Dimension size = new Dimension();
    Point pt;//Maintain the Current Pressed Values of Mouse
    Rectangle rect;//Maintain the moving position of Mouse     public LoadAndShow(BufferedImage image)     {
    this.image = image;
    size.setSize(image.getWidth(), image.getHeight());
    this.addMouseListener(this);
    this.addMouseMotionListener(this);
    * Drawing an image can allow for more
    * flexibility in processing/editing.
    protected void paintComponent(Graphics g) {
    // Center image in this component.
    int x = (getWidth() - size.width)/2;
    int y = (getHeight() - size.height)/2;
    g.drawImage(image, x, y, this);
    }     public Dimension getPreferredSize() { return size; }     public static void main(String[] args) throws IOException {
    //set the image path
    String path = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Winter.jpg";
    BufferedImage image = ImageIO.read(new File(path));
    LoadAndShow test = new LoadAndShow(image);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setResizable(false);
    f.add(test);
    f.setSize(400,400);
    f.setLocation(200,200);
    f.setVisible(true);
    //showIcon(image);
    * Easy way to show an image: load it into a JLabel
    * and add the label to a container in your gui.
    private static void showIcon(BufferedImage image) {
    ImageIcon icon = new ImageIcon(image);
    }     public void mouseClicked(MouseEvent e) {
    }     public void mousePressed(MouseEvent e) {
    pt = e.getPoint();
    rect = this.getBounds();
    }     public void mouseReleased(MouseEvent e) {
    }     public void mouseEntered(MouseEvent e) {
    }     public void mouseExited(MouseEvent e) {
    }     public void mouseDragged(MouseEvent e) {
    Point p=e.getPoint();
    moveImageOnMouseMove(p);
    }     public void mouseMoved(MouseEvent e) {
    * This Function is used for calculate the Dragging point of Mouse and set the image on particular points
    * @param p Point hold the dragging point of Mouse
    private void moveImageOnMouseMove(Point p)
    int xDelta = p.x - pt.x;
    int yDelta = p.y - pt.y;
    rect.x = rect.x + xDelta;
    rect.y = rect.y + yDelta;
    this.setLocation(rect.x, rect.y);
    this.repaint();
    }}   If you have any query related with the code please let me know.
    Manish L
    MS Technology
    www.ms-technology.com
    Edited by: mannymst on Sep 18, 2008 5:53 AM
    Edited by: mannymst on Sep 18, 2008 6:05 AM

  • How to load mutiple image

    I'm trying to create a photo manager but I can't find a way to load multiple images onto my frame. I have a thumbnail class that makes thumbnails for an image (which is a modified version of the class ImageHolder from FilthyRichClient)
    public class Thumbnails {
         private List<BufferedImage> scaledImages = new ArrayList<BufferedImage>();
    private static final int AVG_SIZE = 160;
    * Given any image, this constructor creates and stores down-scaled
    * versions of this image down to some MIN_SIZE
    public Thumbnails(File imageFile) throws IOException{
              // TODO Auto-generated constructor stub
         BufferedImage originalImage = ImageIO.read(imageFile);
    int imageW = originalImage.getWidth();
    int imageH = originalImage.getHeight();
    boolean firstScale = true;
    scaledImages.add(originalImage);
    while (imageW >= AVG_SIZE && imageH >= AVG_SIZE) {
         if(firstScale && (imageW > 320 || imageH > 320)) {
              float factor = (float) imageW / imageH;
              if(factor > 0) {
              imageW = 320;
              imageH = (int) (factor * imageW);
              else {
                   imageH = 320;
                   imageW = (int) (factor * imageH);
         else {
              imageW >>= 1;
         imageH >>= 1;
    BufferedImage scaledImage = new BufferedImage(imageW, imageH,
    originalImage.getType());
    Graphics2D g2d = scaledImage.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.drawImage(originalImage, 0, 0, imageW, imageH, null);
    g2d.dispose();
    scaledImages.add(scaledImage);
    * This method returns an image with the specified width. It finds
    * the pre-scaled size with the closest/larger width and scales
    * down from it, to provide a fast and high-quality scaled version
    * at the requested size.
    BufferedImage getImage(int width) {
    for (BufferedImage scaledImage : scaledImages) {
    int scaledW = scaledImage.getWidth();
    // This is the one to scale from if:
    // - the requested size is larger than this size
    // - the requested size is between this size and
    // the next size down
    // - this is the smallest (last) size
    if (scaledW < width || ((scaledW >> 1) < width) ||
    (scaledW >> 1) < (AVG_SIZE >> 1)) {
    if (scaledW != width) {
    // Create new version scaled to this width
    // Set the width at this width, scale the
    // height proportional to the image width
    float scaleFactor = (float)width / scaledW;
    int scaledH = (int)(scaledImage.getHeight() *
    scaleFactor + .5f);
    BufferedImage image = new BufferedImage(width,
    scaledH, scaledImage.getType());
    Graphics2D g2d = image.createGraphics();
    g2d.setRenderingHint(
    RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.drawImage(scaledImage, 0, 0,
    width, scaledH, null);
    g2d.dispose();
    scaledImage = image;
    return scaledImage;
    // shouldn't get here
    return null;
    A loop will loop through a collection of files and pass them to the constructor of Thumbnails to create thumbnails and then set them as icon for JLabels that will be added to a JPanel, but it throws a java.lang.OutOfMemoryError at this line:
    BufferedImage originalImage = ImageIO.read(imageFile);
    even when there're only about 8 image files in the collection (total size 2,51MB).
    I've seen other people's software that could load hundreds of photos in a matter of seconds! How do I suppose to do that? How to load mutiple images efficiently? Please help!! Thanks a lot!

    another_beginner wrote:
    Thanks everybody! I appreciate your help! I don't understand why but when I use a separate thread to do the job, that problem disappear. You were likely doing your image loading and thumnail creation on the Event Dispatching Thread. Among other things, this is the same thread that updates and paints your panels, frames, buttons, ect.. When a programer does something computationaly expensive on the event dispatching thread then the GUI becomes unresponsive until the computation is done.
    Ideally what you want to do is load images and create thumnails on a seperate thread and update your GUI on the event dispatching thread. I supect that while you are finally doing the first item, you might now be violating the second item.
    Whatever, the program seems to be pretty slow on start up 'cause it have to reload images everytime. I'm using Picasa and it can display those thumbnails almost instantly. I know that program is made by professionals. But I still want to know how.I took a look at this Picasa you mentioned. It's the photo manager from google right? You're right in that the thumnails display instantly when starting up. This is because Picasa is actually saving the thumnails, instead of creating them everytime the program starts up. It only creates the thumnails once (when you import a picture) and saves the thumnail data to " +*currentUser*+ /AppData/Local/Google/Picasa2/db3/" (at least on my computer --> Vista).
    Also, if your looking for speed then for some inexplicable reason java.awt.Toolkit.getDefaultToolkit().createImage(...); is faster (sometimes much faster) than ImageIO.read(...). But there comes a price in dealing with Toolkit images. A toolkit image isn't ready for anything until it has been properly 'loaded' using one of several methods. Also, when you're done and ready for the image to be garbage collected then you need to call Image.flush() or you will eventually find yourself with an out of memory error (BufferedImages don't have this problem). Lastly, Toolkit.createImage(...) can only read image files that the older versions of java supported (jpg, png, gif, bmp) .
    And, another question (or maybe I should post it in a different thread?), I can't display all thumbnails using a JPanel because it has a constant height unless I explicitly set it with setPreferredSize. Even when put in a JScrollPane, the height doesn't change so the scrollbar doesn't appear. Anyone know how to auto grow or shrink a JPanel vertically? Or I have to calculate the preferred height by myself?Are you drawing the thumnails directly on the JPanel? If so then you will indeed need to dynamically set the preferred size of the component.
    If not, then presumebly your wrapping the thumnails in something like a JLabel or JButton and adding that to the panel. If so, what is the layout manager you're using for the panel?

Maybe you are looking for