How to draw JLabel?

I want to use the 2D Java API to draw on a JLabel that already has an image, and then save the resulting edited image.

I cannot find tutorials on this particular issue, does anyone have any code or links that show how to do this?

+5
source share
2 answers

One approach would be to make an existing image and drawing in BufferedImage, as shown in this, which overlays the text on the logo. After completing the image, use ImageIO.write()to save it in the desired format.

+3
source

paintComponent JLabel. super.paintComponent, JLabel, . :

public void paintComponent(Graphics g){
    super.paintComponent(g)
    g.drawWhatever ...
}
+4

All Articles