Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
01-04-2011, 09:00 PM #1
- Join Date
- Sep 2002
- Washington, DC
- Thanked 0 Times in 0 Posts
Swing, ImageIcon, Slider and BufferedImage
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.
01-09-2011, 12:23 AM #2
- Join Date
- Dec 2005
- Thanked 79 Times in 79 Posts
you have the same problem as here:
Components not repainting until function completes
You should stick thread somewhere into your code.