Bonjour à tous,
Je suis en train de créer un splashscreen pour charger le projet de mon application.
Le problème est l'image, j'ai choisi une image transparente que j'hérite d'un Jpanel.
Le problème est que l'image se définie par rapport en haut de la page.
Voir l'image ci jointe:
L'image reprend le fond de la page en haut a gauche.
Voici mon code:
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 public class SplashScreen extends JPanel{ BufferedImage image = null; public SplashScreen(Image image) { this.image = (BufferedImage) image; } public SplashScreen() { } /** * @param image * @uml.property name="image" */ public void setImage(BufferedImage image){ this.image = image; } public Image getImage(BufferedImage image){ return image; } public void paint(Graphics g){ if(image.getColorModel().hasAlpha()){ try{ Robot robot = new Robot(); BufferedImage fond = robot.createScreenCapture(getBounds()); MediaTracker tracker = new MediaTracker(this); tracker.addImage(fond,0); tracker.waitForAll(); g.drawImage(fond, 0,0,null); }catch(Exception e){e.printStackTrace();} } g.drawImage(image,0,0,null); } }Merci de votre aide
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 public Main(){ try { splash = new SplashScreen(ImageIO.read(new File("images/splashscreen.gif"))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } progressBar = new JProgressBar(); //JPanel content = new JPanel(new BorderLayout()); //content.add(splash); //content.add(progressBar, BorderLayout.SOUTH); fen_splash= new JWindow(); fen_splash.setLayout(new BorderLayout()); fen_splash.add(splash, BorderLayout.CENTER); fen_splash.add(progressBar, BorderLayout.SOUTH); fen_splash.setSize(450, 300);//On lui donne une taille pour qu'on puisse la voir fen_splash.setLocationRelativeTo(null); //fen_splash.setAlwaysOnTop(true); fen_splash.setVisible(true); }![]()
Partager