Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw on a JLabel?

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

I can't find any tutorials on this specific subject, does anyone have any code or references that show how to do it?

like image 361
James MV Avatar asked Dec 11 '11 17:12

James MV


1 Answers

override the paintComponent method of the JLabel. It should first call super.paintComponent, so you get whatever the JLabel contains, then add your own drawing code after that. Should look somewhat like this:

public void paintComponent(Graphics g){
    super.paintComponent(g)
    g.drawWhatever ...
}
like image 61
Jens Schauder Avatar answered Nov 05 '22 22:11

Jens Schauder