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

Interfaces Graphiques en Java Discussion :

Java - Problème de Look'n'Feels


Sujet :

Interfaces Graphiques en Java

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 282
    Points : 119
    Points
    119
    Par défaut Java - Problème de Look'n'Feels
    Bonjour,
    Grâce à la page
    http://www.developpez.net/forums/arc...p/t-51382.html

    j'ai intégré 2 look'n'Feel dans mon appli :
    "Tonic" et "Quaqua".

    J'ai une petite fenêtre permettant de choisir les look'n'feel listés dans une combo.
    J'ai un événement sur la combo qui applique le thème à la fenêtre dès sa sélection, et qui l'applique à l'interface principale si on sort de la fenêtre avec OK.

    Cependant dès que je choisis l'un de ces deux thèmes (les "DefaultLookAndFeel" fournis avec la JDK ne posent aucun pb), j'obtiens des Exceptions de ce genre :

    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
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at ch.randelshofer.quaqua.QuaquaScrollBarUI.getTrackAndButtonsBorder(QuaquaScrollBarUI.java:288)
    	at ch.randelshofer.quaqua.QuaquaScrollBarUI.paintTrack(QuaquaScrollBarUI.java:213)
    	at javax.swing.plaf.basic.BasicScrollBarUI.paint(Unknown Source)
    	at ch.randelshofer.quaqua.QuaquaScrollBarUI.paint(QuaquaScrollBarUI.java:145)
    	at javax.swing.plaf.ComponentUI.update(Unknown Source)
    	at javax.swing.JComponent.paintComponent(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JSplitPane.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JSplitPane.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JLayeredPane.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
    	at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
    	at javax.swing.JComponent._paintImmediately(Unknown Source)
    	at javax.swing.JComponent.paintImmediately(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Ensuite à chaque fois que j'essaye de re-changer de thème l'affichage empire et les exceptions pleuvent.

    Voici un bout de mon code :

    D'abord la méthode qui récupère la liste des thèmes standards et les insère dans un ArrayList, et insère à la fin les deux thèmes additionnels :

    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
      public ArrayList getLookAndFeelsList() {
        UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
        lookAndFeelList = new ArrayList();
        for (int i=0; i<info.length; i++) {
          MyLookAndFeel mlaf = new MyLookAndFeel (info[i]);
          lookAndFeelList.add (mlaf);
        }
        TonicLookAndFeel tlaf = new TonicLookAndFeel();
        UIManager.LookAndFeelInfo tmp = new UIManager.LookAndFeelInfo (tlaf.getName(), "com.digitprop.tonic.TonicLookAndFeel");
        MyLookAndFeel tmp1 = new MyLookAndFeel (tmp);
        lookAndFeelList.add (tmp1);
     
        QuaquaLookAndFeel qqlaf = new QuaquaLookAndFeel();
        tmp = new UIManager.LookAndFeelInfo (qqlaf.getName(), "ch.randelshofer.quaqua.QuaquaLookAndFeel");
        tmp1 = new MyLookAndFeel (tmp);
        lookAndFeelList.add (tmp1);
     
        return lookAndFeelList;
      }
    Voici ma classe "MyLookAndFeel" :

    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
     
    public class MyLookAndFeel {
     
        private UIManager.LookAndFeelInfo lafi;
     
        public MyLookAndFeel (UIManager.LookAndFeelInfo lafi) {
          this.lafi = lafi;
        }
     
        public String toString() {
          return this.lafi.getName();
        }
     
        public UIManager.LookAndFeelInfo getLafi() {
          return this.lafi;
        }
     
    }

    Voilà, merci à vous si vous me sortez de ces bugs graphiques...!

  2. #2
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 282
    Points : 119
    Points
    119
    Par défaut Autre exemple d'Exception
    Voici une autre erreur obtenue si dès le lancement de mon appli l'un des deux thèmes additionnels est sélectionné par défaut :

    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
     
    Warning: ch.randelshofer.quaqua.util.Preferences failed to load Mac OS X global system preferences
     
    java.io.FileNotFoundException: C:\Documents and Settings\userXXX\Library\Preferences\.GlobalPreferences.plist (The system cannot find the path specified)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileReader.<init>(Unknown Source)
    	at ch.randelshofer.quaqua.util.Preferences.readPList(Preferences.java:107)
    	at ch.randelshofer.quaqua.util.Preferences.loadGlobalPreferences(Preferences.java:74)
    	at ch.randelshofer.quaqua.util.Preferences.get(Preferences.java:45)
    	at ch.randelshofer.quaqua.util.Preferences.getString(Preferences.java:39)
    	at ch.randelshofer.quaqua.BasicQuaquaLookAndFeel.initSystemColorDefaults(BasicQuaquaLookAndFeel.java:169)
    	at ch.randelshofer.quaqua.tiger.Quaqua14TigerCrossPlatformLookAndFeel.initSystemColorDefaults(Quaqua14TigerCrossPlatformLookAndFeel.java:75)
    	at ch.randelshofer.quaqua.BasicQuaquaLookAndFeel.getDefaults(BasicQuaquaLookAndFeel.java:110)
    	at ch.randelshofer.quaqua.LookAndFeelProxy.getDefaults(LookAndFeelProxy.java:198)
    	at javax.swing.UIManager.setLookAndFeel(Unknown Source)
    	at javax.swing.UIManager.setLookAndFeel(Unknown Source)

  3. #3
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Quaqua ne fonctionne que sous macos(il se sert des ressources du L&F mac), pas sous windows.... D'où les erreurs que tu obtiens.
    Désolé mister
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 282
    Points : 119
    Points
    119
    Par défaut
    Citation Envoyé par sinok
    Quaqua ne fonctionne que sous macos(il se sert des ressources du L&F mac), pas sous windows....
    Désolé mister
    Ah autant pour moi... c dommage...
    Et pour Tonic, aucune limitation n'est mentionnée sur la page :
    http://www.digitprop.com/p.php?page=toniclf&lang=eng

    Et ça plante aussi...
    Pour ce thème j'obtiens :

    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
     
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at com.digitprop.tonic.SplitPaneDivider.oneTouchExpandableChanged(SplitPaneDivider.java:70)
    	at javax.swing.plaf.basic.BasicSplitPaneDivider.setBasicSplitPaneUI(Unknown Source)
    	at javax.swing.plaf.basic.BasicSplitPaneDivider.<init>(Unknown Source)
    	at com.digitprop.tonic.SplitPaneDivider.<init>(SplitPaneDivider.java:56)
    	at com.digitprop.tonic.SplitPaneUI.createDefaultDivider(SplitPaneUI.java:57)
    	at javax.swing.plaf.basic.BasicSplitPaneUI.installDefaults(Unknown Source)
    	at javax.swing.plaf.basic.BasicSplitPaneUI.installUI(Unknown Source)
    	at com.digitprop.tonic.SplitPaneUI.installUI(SplitPaneUI.java:64)
    	at javax.swing.JComponent.setUI(Unknown Source)
    	at javax.swing.JSplitPane.setUI(Unknown Source)
    	at javax.swing.JSplitPane.updateUI(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI0(Unknown Source)
    	at javax.swing.SwingUtilities.updateComponentTreeUI(Unknown Source)
    	at dvdorganizer.Preferences.jButtonOK_actionPerformed(Preferences.java:141)
    	at dvdorganizer.Preferences$1.actionPerformed(Preferences.java:83)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

    Any help ?
    Merci d'avance !

  5. #5
    Membre émérite
    Avatar de xavlours
    Inscrit en
    Février 2004
    Messages
    1 832
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 1 832
    Points : 2 410
    Points
    2 410
    Par défaut
    Bonjour,

    je sors du code source de Tonic ui, et la ligne mentionnée dans la stack trace ne peut pas poser de problèmes de NullPointerException. Je te la cite :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(ui.getSplitPane()!=null && ui.getSplitPane().isOneTouchExpandable())
    Sachant que la variable ui est privée, initialisée dans le constructeur par copie d'un this et jamais retouchée après.

    Je peux me tromper, mais quelle JVM utilises-tu ? Celle de Sun ou une autre ? As-tu utilisé un débuggeur ?
    "Le bon ni le mauvais ne me feraient de peine si si si je savais que j'en aurais l'étrenne." B.V.
    Non au langage SMS ! Je ne répondrai pas aux questions techniques par MP.
    Eclipse : News, FAQ, Cours, Livres, Blogs.Et moi.

  6. #6
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 282
    Points : 119
    Points
    119
    Par défaut
    Citation Envoyé par xavlours
    Bonjour,

    je sors du code source de Tonic ui, et la ligne mentionnée dans la stack trace ne peut pas poser de problèmes de NullPointerException. Je te la cite :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(ui.getSplitPane()!=null && ui.getSplitPane().isOneTouchExpandable())
    Sachant que la variable ui est privée, initialisée dans le constructeur par copie d'un this et jamais retouchée après.

    Je peux me tromper, mais quelle JVM utilises-tu ? Celle de Sun ou une autre ? As-tu utilisé un débuggeur ?
    Salut Xavlours,
    J'utilise la JDK SUN officielle 1.5.0_07...
    Rien à faire j'ai vérifié mon code et l'exception, j'obtiens toujours une null pointer exception.

    Part contre ce qui est bizarre c'est que lorsque j'applique le thème à la fenêtre courante il n'y a pas de pb.
    L'exception est levée lorsque j'applique le thème à ma fenêtre principale en fermant ma petite fenêtre de sélection (bouton OK) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        this.jf.setEnabled (true);      // jf = fenêtre principale
        SwingUtilities.updateComponentTreeUI (jf);
        this.dispose();                   // this = fenêtre de sélection de skin
    Ceci sera peut-être plus parlant ?...
    Merci d'avance !

  7. #7
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 282
    Points : 119
    Points
    119
    Par défaut
    Ne pourrait-il pas s'agir d'une incompatibilité entre ce thème Tonic et les librairies Borland Jbuilder ? j'utilise en effet certains objets de Borland (VerticalFlowLayout par exemple...)

  8. #8
    Membre émérite
    Avatar de xavlours
    Inscrit en
    Février 2004
    Messages
    1 832
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 1 832
    Points : 2 410
    Points
    2 410
    Par défaut
    A priori, il ne devrait pas y avoir de conflit avec un Layout quelconque.

    As-tu utilisé un debuggeur pour savoir quelle variable est à null ? Si je ne me trompe pas, ça ne peut être que ui, mais c'est très bizarre.
    "Le bon ni le mauvais ne me feraient de peine si si si je savais que j'en aurais l'étrenne." B.V.
    Non au langage SMS ! Je ne répondrai pas aux questions techniques par MP.
    Eclipse : News, FAQ, Cours, Livres, Blogs.Et moi.

  9. #9
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2004
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2004
    Messages : 282
    Points : 119
    Points
    119
    Par défaut
    Citation Envoyé par xavlours
    A priori, il ne devrait pas y avoir de conflit avec un Layout quelconque.

    As-tu utilisé un debuggeur pour savoir quelle variable est à null ? Si je ne me trompe pas, ça ne peut être que ui, mais c'est très bizarre.
    Le debugger de JBuilder ne me permet pas de remonter plus loin que :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
              UIManager.setLookAndFeel (tmp.getClassName());
              SwingUtilities.updateComponentTreeUI (this);
    Où la deuxième ligne lève l'exception...

    Sinon je crois que je vais laisser tomber cette fonctionalité et ne laisser que les thèmes java (très moches pour la plupart des 4) par défaut.
    J'espérais pouvoir poser des jars dans les sources pour qu'ils soient chargés dynamiquement, mais c pas possible, chaque thème a sa propre bibliothèque et il faut écrire du code spécifique.

    Pour les skins à la Winamp je rêvais un peu

    Merci en tout cas !

Discussions similaires

  1. Problème de Look and Feel non appliqué lors de "java -jar .."
    Par olivier57b dans le forum Agents de placement/Fenêtres
    Réponses: 1
    Dernier message: 29/10/2011, 13h53
  2. Problème utilisation Look and Feel
    Par dimou59 dans le forum Débuter
    Réponses: 7
    Dernier message: 09/05/2011, 15h27
  3. [java 1.4] créer son look and feel
    Par orelero dans le forum Interfaces Graphiques en Java
    Réponses: 6
    Dernier message: 25/04/2006, 18h29
  4. [JTable]Problême de Look and Feel???
    Par D-Phaz dans le forum Composants
    Réponses: 1
    Dernier message: 05/08/2005, 15h24
  5. [look and feel] Linux me pose un problème
    Par -=Spoon=- dans le forum AWT/Swing
    Réponses: 13
    Dernier message: 26/09/2004, 23h23

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