-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFancyTextArea.java
More file actions
54 lines (45 loc) · 1.28 KB
/
FancyTextArea.java
File metadata and controls
54 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import javax.swing.JTextArea;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.Color;
/**
* Comme une JTextArea, mais avec une image de fond
* Idee trouvee sur stackoverflow https://stackoverflow.com/questions/26386422/how-to-set-background-image-to-a-jtextarea-in-a-jpanel
* @author Clément Chomicki
*/
public class FancyTextArea extends JTextArea
{
private BufferedImage aImg;
public FancyTextArea(final BufferedImage pImage)
{
this();
this.aImg = pImage;
}
public FancyTextArea()
{
super();
super.setOpaque(false);
super.setBackground(new Color(10, 23, 0));
super.setForeground(new Color(150, 180, 100));
}
public void setImage(final BufferedImage pImage)
{
this.aImg = pImage;
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
if (this.aImg != null) {
int x = this.getWidth() - this.aImg.getWidth();
int y = this.getHeight() - this.aImg.getHeight();
g.drawImage(this.aImg, x, y, this);
}
else
{
System.out.println("La frame n'a pas d'image");
}
super.paintComponent(g);
g.dispose();
}
}