How to add an image to a JPanel?

前端 未结 14 1534
陌清茗
陌清茗 2020-11-22 00:01

I have a JPanel to which I\'d like to add JPEG and PNG images that I generate on the fly.

All the examples I\'ve seen so far in the Swing Tutorials, specially in the

14条回答
  •  不知归路
    2020-11-22 00:39

    1. There shouldn't be any problem (other than any general problems you might have with very large images).
    2. If you're talking about adding multiple images to a single panel, I would use ImageIcons. For a single image, I would think about making a custom subclass of JPanel and overriding its paintComponent method to draw the image.
    3. (see 2)

提交回复
热议问题