Salut,

voila je suis en train de faire un splash screen pour une appli.
jusque la pas de probleme.
Des infos sont affichées sur le splash screen decrivant l'etat d'initialisation de l'appli (via un JLabel). Jusque la pas de probleme non plus.

j'ai ensuite trouvé sur le blog de Gfx comment donner un effet ombré a mon splashscreen. Genial sauf que lorsque le texte du jpanel est mis a jour, celui ci reste opaque (et efface donc l'arriere plan du splash screen)

ci quelqu'un voit comment faire pour que le font soit également redessiné !

merci de votre aide

ci dessous le code du splashscreen avec le main() qui simule un refraichissement executé normalement par l'appli

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
 
public class SplashScreen extends JWindow {
 
	private BufferedImage splash = null;
 
	/**
         * 
         */
	private static final long serialVersionUID = -4477825196297585512L;
	protected JLabel info;
	protected JLabel version = null;
 
 
	public SplashScreen(BufferedImage image) {
 
		createShadow(image);
		createLabel();
 
	}
 
	private void createShadow(BufferedImage image) {
		int width = image.getWidth();
		int height = image.getHeight();
		int extra = 14;
 
		setSize(new Dimension(width + extra, height + extra));
		setLocationRelativeTo(null);
		Rectangle windowRect = getBounds();
 
		splash = new BufferedImage(width + extra, height + extra,
				BufferedImage.TYPE_INT_ARGB);
 
		Graphics2D g2 = (Graphics2D) splash.getGraphics();
 
		try {
			Robot robot = new Robot(getGraphicsConfiguration().getDevice());
			BufferedImage capture = robot.createScreenCapture(new Rectangle(
					windowRect.x, windowRect.y, windowRect.width + extra,
					windowRect.height + extra));
			g2.drawImage(capture, null, 0, 0);
		} catch (AWTException e) {
		}
 
		BufferedImage shadow = new BufferedImage(width + extra, height + extra,
				BufferedImage.TYPE_INT_ARGB);
		Graphics g = shadow.getGraphics();
		g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
		g.fillRoundRect(6, 6, width, height, 12, 12);
 
		g2.drawImage(shadow, getBlurOp(7), 0, 0);
		g2.drawImage(image, 0, 0, this);
	}
 
	private ConvolveOp getBlurOp(int size) {
		float[] data = new float[size * size];
		float value = 1 / (float) (size * size);
		for (int i = 0; i < data.length; i++) {
			data[i] = value;
		}
		return new ConvolveOp(new Kernel(size, size, data));
	}
 
	private void createLabel() {
 
		GridLayout l = new GridLayout(12, 3);
		this.getContentPane().setLayout(l);
 
		info = new JLabel(); // <html><b>Initialization ....</html>
		info.setOpaque(false);
 
		for (int i = 0; i < 34; i++) {
			JPanel blank1 = new JPanel();
			blank1.setOpaque(false);
			this.getContentPane().add(blank1);
		}
 
		version = new JLabel("<html><b>Version: prototype</html>");
		version.setOpaque(false);
		this.getContentPane().add(version);
		this.getContentPane().add(info);
 
	}
 
	public void setInfoText(String s) {
		info.setText(s);
		info.paintImmediately(0, 0, info.getWidth(), info.getHeight());
	}
 
	public JLabel getInfo() {
		return info;
	}
 
	public void paint(Graphics g) {
		if (splash != null) {
			g.drawImage(splash, 0, 0, null);
		}
	}
 
	public static void main(String[] args) {
		try {
 
			final BufferedImage image = ImageIO.read(new File ("splash.png"));
 
			javax.swing.SwingUtilities.invokeLater(new Runnable() {
				public void run() {
 
					final SplashScreen window = new SplashScreen(image);
					window.setVisible(true);
					Timer timer = new Timer(2000, new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							window.setInfoText("<html><b>Loading ... </html>");
							try {
								Thread.sleep(5000);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
							System.exit(0);
						}
					});
					timer.start();
				}
			});
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
	public JLabel getVersionLabel() {
		return version;
	}