I made a JxImageView object and set an image to it, now i got white color as its background which is not in the original image. i just want to remove the white color from the viewport.
-
What is a JxImageView? Edit: ah, [I see](http://javadoc.geotoolkit.org/external/swingx/org/jdesktop/swingx/JXImageView.html). Let me add the SwingX tag to your question. – Hovercraft Full Of Eels Jan 14 '12 at 13:53
-
What if you call setOpaque(false) on the JxImageView object? – Hovercraft Full Of Eels Jan 14 '12 at 13:56
-
setOpaque(false) didn't help. – Bijoy Jan 14 '12 at 13:58
-
If you call `getImage()` on your JxImageView object after obtaining the image, and view the image, does it still have a white background? If so, then perhaps the image isn't getting read into Java correctly and is losing its transparency. You may have to show us some code. – Hovercraft Full Of Eels Jan 14 '12 at 14:01
-
[link](http://pastebin.com/rgvM2v7V) there is some netbeans junk code in it. – Bijoy Jan 14 '12 at 14:14
-
bug filed: java.net/jira/browse/SWINGX-1479 – kleopatra Jan 14 '12 at 15:49
3 Answers
I don't know JxImageView, but I don't see how it could change the background color of an image, because an image doesn't have any background color. It probably just means that some parts of the image are transparent, and that the white color you see is the background color of the component which displays the image: JxImageView
. You should just probably change the background color of the JxImageView
, to the color that suits you.
The JxImageView could also itself be transparent, in which case you would see its parent component's background.
Try loading the image in an image editor to confirm that the image is transparent.

- 678,734
- 91
- 1,224
- 1,255
-
I confirmed that background of image is transparent. Also i changed background color of the component but that also didn't work. – Bijoy Jan 14 '12 at 14:33
-
2So, my answer is correct, but unfortunately, Adel Boutros's answer is also correct, and you won't be able to change the background of JXImageView. Either make your own component, or subclass JXImageView and override paintComponent in order to paint the background. I would submit a bug/evolution report to swingx, because I find it dumb to be unable to set the background of such a component. – JB Nizet Jan 14 '12 at 14:40
-
2@Bijoy definitely a bug: JXImagePanel _is-a_ JXPanel and as such should respect an arbitrary background painter (instead of by-passing super completely) Please file an issue in the SwingX issue tracker so we don't forget to fix it in the next release :-) – kleopatra Jan 14 '12 at 14:57
-
BufferedImage img=ImageIO.read(new File("imagename"));
jXImagePanel1.setImage(img); solved the issue. – Bijoy Jan 14 '12 at 15:28 -
@Bijoy hmm ... maybe I misunderstood the problem (notwithstanding the fact that JXImageView must respect a potentially set background painter) - you mean you got the unexpected white color _inside_ the image? If so, that's most probably not an issue with JXImagePanel but with the transparency of the image just as JBNizet guessed. – kleopatra Jan 14 '12 at 15:43
-
After reading the docs, I conclude (correct me if I am wrong) you can't change the white background
In the Constructor of JxImageView, you see:
/** Creates a new instance of JXImageView */
public JXImageView() {
checkerPaint = ColorUtil.getCheckerPaint(Color.white,
new Color(250, 250, 250), 50);
setEditable(true);
}
and checkerPaint cannot be accessed

- 10,205
- 7
- 55
- 89
JXImageView bug fixed in the current snapshot (btw, post-SwingX 1.6.3, just in case you missed the release announcement :) To replace the default checkered background, simply set a custom background painter:
JXImageView ipa = new JXImageView();
ipa.setBackgroundPainter(new MattePainter(Color.RED));

- 51,061
- 28
- 99
- 211