2

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Bijoy
  • 399
  • 2
  • 7
  • 15

3 Answers3

4

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.

JB Nizet
  • 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
  • 2
    So, 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
  • bug filed: java.net/jira/browse/SWINGX-1479 – kleopatra Jan 14 '12 at 15:48
4

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

Adel Boutros
  • 10,205
  • 7
  • 55
  • 89
3

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));
kleopatra
  • 51,061
  • 28
  • 99
  • 211