Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2002
    Location
    Washington, DC
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Swing, ImageIcon, Slider and BufferedImage

    Hi,all.

    Somewhat complicated issue I'm having with some code - please bear with me as I explain:

    I have a Swing application that has two JLabel areas separated by a JSlider. The left JLabel shows an original image from a series, the right a processed image, and the slider selects which image of the series to display. The intention is to have each JLabel change as the slider is moved along the series to the correct numbered original image and corresponding processed image. At the moment, this works for the original image JLabel, but not for the processed.

    I have a data structure that holds the information for each image in the series: the original image is stored as a File variable, the processed image is stored as a vector of x-y coordinate structures denoting pixels. The slider selects from a vector of these structures and works with the associated information.

    When the slider changes value, I set the original image JLabel's ImageIcon using getImage on the File variable for the image. I then set the processed image JLabel ImageIcon to a new ImageIcon using a bufferedImage returned from my data structure. This works when I process an image, but when I return to it using the slider the generated image does not display correctly.

    I have a conditional test to see if an image already has a processed image in the structure and try to pull that up when the slider changes value, but when the statement returns true it pulls up the processed image of the last processed original image (i.e., the last to be shown in the JLabel), not the current.

    Can someone tell me why this might be happening? Is there a delay in creating a bufferedImage when changing a JLabel?

    Any help would be appreciated - code is available if needed.

    Thanks!

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts
    you have the same problem as here:
    Components not repainting until function completes
    You should stick thread somewhere into your code.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •