JFrame transparente, suite.
Je reprends ce thread qui abordait le déjà le sujet mais qui est marqué comme Résolu.
Au contraire à ce que rootel77 y disait, je trouve que le résultat avec Robot est plutôt convainquant.
Je me suis inspiré pour du lien fournit par GETah pour mettre un fond transparent à ma JFrame.
Là où je bloque, c'est que je n'arrive pas à peindre mes objets (bouton, ...) à moins de perdre mon fond transparent.
Voici mon code:
Code:
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
| /**
* Redessin de l'écran
* @param g Graphics
*/
public void paint(Graphics g) {
if (fond != null) {
g.drawImage(fond, 0, 0, null);
}
// :-( fait disparaître l'image "fond", mais sans ça impossible de voir mon bouton !!!
super.paint(g);
}
/**
* Construction du fond
*/
private void BuildFond() {
Rectangle r = this.getBounds();
// Capture du fond
fond = new BufferedImage(W, H, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) fond.getGraphics();
try {
Robot robot = new Robot(getGraphicsConfiguration().getDevice());
BufferedImage capture = robot.createScreenCapture(r);
g2.drawImage(capture, null, 0, 0);
} catch (AWTException e) {}
// La couche orange transaparente
g2.setColor(new Color(0.95F, 0.5F, 0F, 0.65F));
g2.fillRoundRect(0, 0, W, H, 0, 0);
} |
BuildFond est appellé à la construction.
J'ai essayé d'ajouter un getRootPane().setOpaque(false) mais ça n'a servi à rien.
D'autres idées, conseils ?
Merci,
Laurent
JNA met dit "Window alpha not supported"
J'ai investigué un peu, mais la manière de mettre en œuvre ce JNA n'est pas très claire !
Mon code est simplissime.
Code:
import com.sun.jna.examples.*;
Si je fais dans mon main:
Code:
1 2
| ShapedWindowDemo o=new ShapedWindowDemo();
o.main(new String[0]); |
j'obtiens l'horloge avec fond transparent.
Par contre si j'écris:
Code:
1 2 3 4 5
| JFrame frame = new SelectionWindow();
frame.setVisible(true);
if (WindowUtils.isWindowAlphaSupported())
WindowUtils.setWindowAlpha(frame, 0.5f);
else WindowUtils.setWindowTransparent(frame,true); |
Je reçois un "Window alpha not supported".
Ma fenêtre n'est en rien transparente !!
Que font-ils de plus dans cette ShapdeWindowDemo ???