IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

Image ne veut pas s'afficher


Sujet :

AWT/Swing Java

  1. #1
    Membre habitué Avatar de krolineeee
    Inscrit en
    Mars 2006
    Messages
    232
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 232
    Points : 173
    Points
    173
    Par défaut Image ne veut pas s'afficher
    Bonjour,

    J'essaye en vain de créer une petite fenêtre de chargement.
    C'est bête et méchant cette JFrame ne se compose au final que d'une image.
    Alors dans le concepteur, c'est nikel elle s'affiche mais dès que je lance l'appli, rien a faire ça m'ouvre une fenêtre grise (seul point positif : elle a la bonne taille)

    un petit bout de code pour vous éclairer :
    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
     
    this.setTitle("Chargement en cours...");
            setSize(new Dimension(260, 220));
            jPanel1 = new JPanel();
            jPanel1.setLayout(xYLayout1);
            jPanel1.setBorder(null);
            this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
     
            image = new ImageIcon(ReportingCatalogueV2.class.getResource(
                    "chargCatv2.gif"));
            jLabel1 = new JLabel();
            jLabel1.setBackground(Color.pink);
            jLabel1.setOpaque(true);
            jLabel1.setIcon(image);
            jPanel1.add(jLabel1, new XYConstraints(5, 5, -1, -1));
    Merci pour votre aide

  2. #2
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,

    Où se trouve l'image "chargCatv2.gif" précisément ?
    Vérifie ce que te retourne la méthode suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ReportingCatalogueV2.class.getResource("chargCatv2.gif")
    a++

  3. #3
    Membre habitué Avatar de krolineeee
    Inscrit en
    Mars 2006
    Messages
    232
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 232
    Points : 173
    Points
    173
    Par défaut
    Elle me retourne ça :
    file:I:/Developpement/Java/jbproject/CatatogueV2/classes/catatoguev2/chargCatv2.gif

    Ce qui correspond bien à l'emplacement de mon image...

  4. #4
    Membre actif Avatar de fumiste972
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Février 2003
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Février 2003
    Messages : 228
    Points : 291
    Points
    291
    Par défaut
    Tu peux montrer le code qui appel et affiche ta JFrame stp.

  5. #5
    Membre habitué Avatar de krolineeee
    Inscrit en
    Mars 2006
    Messages
    232
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 232
    Points : 173
    Points
    173
    Par défaut
    Appel de la fenetre de chargement
    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
    public class ChoixCatalogue extends JFrame {
        JPanel contentPane;
        Database scherzo = new Database();
        QueryDataSet queryDataSetCatal = new QueryDataSet();
        String requete = "  select CAT_LIB, 'En cours' as ETAT, CAT_CODE from cata "
                         + " where cat_date>=trunc(sysdate)"
                         + "   and cat_date<=trunc(sysdate+42)"
                         + " union"
                         + " select CAT_LIB, 'Terminé' as ETAT, CAT_CODE"
                         + "   from cata"
                         + "  where cat_date<trunc(sysdate)"
                         + "    and cat_date>=trunc(sysdate-90)";
        JComboBox jComboBoxCata = new JComboBox();
        JLabel jLabel1 = new JLabel();
        JButton jButtonVisual = new JButton();
        JChargement jchar = new JChargement(); //cree fenetre de chargement
    
        public ChoixCatalogue() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    
        /**
         * Initialisation du composant.
         *
         * @throws java.lang.Exception
         */
        private void jbInit() throws Exception {
            jchar.setVisible(true);//affiche fenetre de chargmt
            contentPane = (JPanel) getContentPane();
    ...

    class Jchargement :
    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
    package catatoguev2;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.BorderLayout;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import java.awt.Dimension;
    import java.awt.Color;
    import javax.swing.JButton;
    import java.awt.Toolkit;
    import java.awt.Rectangle;
    import com.borland.jbcl.layout.XYLayout;
    import com.borland.jbcl.layout.*;
    import javax.swing.BorderFactory;
     
    class JChargement extends JFrame {
        ImageIcon image;
        JLabel jLabel1;
        XYLayout xYLayout1 = new XYLayout();
        public JChargement() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
                // Centrer la fenêtre
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                Dimension frameSize = this.getSize();
                if (frameSize.height > screenSize.height) {
                    frameSize.height = screenSize.height;
                }
                if (frameSize.width > screenSize.width) {
                    frameSize.width = screenSize.width;
                }
                this.setLocation((screenSize.width - frameSize.width) / 2,
                                 (screenSize.height - frameSize.height) / 2);
                this.setVisible(true);
     
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
     
        private void jbInit() throws Exception {
            this.setTitle("Chargement en cours...");
            this.getContentPane().setLayout(xYLayout1);
            setSize(new Dimension(260, 220));
            image = new ImageIcon(ReportingCatalogueV2.class.getResource(
                    "chargCatv2.gif"));
            jLabel1 = new JLabel();
            jLabel1.setOpaque(true);
            jLabel1.setIcon(image);
            this.getContentPane().add(jLabel1, new XYConstraints(5, 5, -1, -1));
        }
    }
    Voilà je ne vois toujours pas ce qui cloche.
    Par contre je sais que ce n'est pas l'image qui pose problème car je n'arrive meme pas a afficher un texte

  6. #6
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par krolineeee
    Par contre je sais que ce n'est pas l'image qui pose problème car je n'arrive meme pas a afficher un texte
    Ce ne serait pas un problème de Layout alors ? C'est quoi ce XYLayout ???

    a++

  7. #7
    Membre habitué Avatar de krolineeee
    Inscrit en
    Mars 2006
    Messages
    232
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 232
    Points : 173
    Points
    173
    Par défaut
    Je me suis aussi posé la question, j'ai tenté sans Layout et le résultat est le meme ....

  8. #8
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par krolineeee
    Je me suis aussi posé la question, j'ai tenté sans Layout et le résultat est le meme ....
    D'après ce que j'ai compris du XYLayout, c'est un layout qui place les composant selon l'origine x,y du parent (un peu comme le null-layout en fait).

    Tu DOIS donc spécifier la taille, et apparemment cela se fait via les deux derniers paramètres de XYConstraints() qui valent -1 chez toi...

    Donc ce serait plutôt normal q'un composant de taille négatif ne soit pas visible...

    a++

    PS : Pourquoi ne pas utiliser un vrai Layout ?

  9. #9
    Membre habitué Avatar de krolineeee
    Inscrit en
    Mars 2006
    Messages
    232
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 232
    Points : 173
    Points
    173
    Par défaut
    ok j'ai tenter avec un BorderLayout :

    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
    class JChargement extends JFrame {
        ImageIcon image;
        JLabel jLabel1;
        BorderLayout borderLayout1 = new BorderLayout();
        public JChargement() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
                // Centrer la fenêtre
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                Dimension frameSize = this.getSize();
                if (frameSize.height > screenSize.height) {
                    frameSize.height = screenSize.height;
                }
                if (frameSize.width > screenSize.width) {
                    frameSize.width = screenSize.width;
                }
                this.setLocation((screenSize.width - frameSize.width) / 2,
                                 (screenSize.height - frameSize.height) / 2);
                this.setVisible(true);
     
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
     
        private void jbInit() throws Exception {
            this.setTitle("Chargement en cours...");
            this.getContentPane().setLayout(borderLayout1);
            setSize(new Dimension(260, 220));
            image = new ImageIcon(ReportingCatalogueV2.class.getResource(
                    "chargCatv2.gif"));
            jLabel1 = new JLabel();
            jLabel1.setOpaque(true);
            jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
            jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
            jLabel1.setIcon(image);
            this.getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
        }
    }
    Résultat... Rien ne s'affiche ! (c'est le symptome du vendredi je crois )

Discussions similaires

  1. Image qui ne veut pas s'afficher
    Par vince85 dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 17/06/2011, 13h40
  2. image qui veut pas s'afficher
    Par mannou83 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 27/05/2009, 22h42
  3. Petit problème d''info-bulle sur image qui veut pas se supprimer
    Par Machiavel dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 01/03/2007, 15h52
  4. L'Image ne veut pas s'afficher !
    Par archipel dans le forum Tkinter
    Réponses: 4
    Dernier message: 19/02/2007, 10h47
  5. JList qui ne veut pas s'afficher
    Par hamham dans le forum Composants
    Réponses: 16
    Dernier message: 29/01/2007, 18h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo