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

NetBeans Java Discussion :

Visibilité icône d'un JavaBean dans NB6.1


Sujet :

NetBeans Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Avatar de fabou3377
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2006
    Messages : 182
    Par défaut Visibilité icône d'un JavaBean dans NB6.1
    Bonjour à tous,

    j'ai créé un JavaBeans qui fonctionne parfaitement. Je l'ai intégré dans ma palette de composants Netbeans... Tout fonctionne sauf un léger détail --> pas d'icône... J'ai créer alors un fichier Bean descriptor à l'aide de la commande Netbeans puis j'ai indiqué le chemin de mes icônes... Lorsque je l'intégre à nouveau dans ma palette aucun icône n'apparaît...

    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
    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
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package graphictools.lib;
     
    import java.beans.*;
     
    /**
     * @author fabrice
     */
    public class Cursor01BeanInfo extends SimpleBeanInfo {
     
        // Bean descriptor                          
        /*lazy BeanDescriptor*/
        private static BeanDescriptor getBdescriptor(){
            BeanDescriptor beanDescriptor = new BeanDescriptor  ( graphictools.lib.Cursor01.class , null ); // NOI18N
            beanDescriptor.setDisplayName ( "Cursor" );                              
     
        // Here you can add code for customizing the BeanDescriptor.
     
            return beanDescriptor;     }                         
     
     
        // Property identifiers                      
        private static final int PROPERTY_level = 0;
     
        // Property array 
        /*lazy PropertyDescriptor*/
        private static PropertyDescriptor[] getPdescriptor(){
            PropertyDescriptor[] properties = new PropertyDescriptor[1];
     
            try {
                properties[PROPERTY_level] = new PropertyDescriptor ( "level", graphictools.lib.Cursor01.class, null, "setLevel" ); // NOI18N
            }
            catch(IntrospectionException e) {
                e.printStackTrace();
            }                          
     
        // Here you can add code for customizing the properties array.
     
            return properties;     }                     
     
        // EventSet identifiers                  
     
        // EventSet array
        /*lazy EventSetDescriptor*/
        private static EventSetDescriptor[] getEdescriptor(){
            EventSetDescriptor[] eventSets = new EventSetDescriptor[0];                      
     
        // Here you can add code for customizing the event sets array.
     
            return eventSets;     }                 
     
        // Method identifiers                   
        private static final int METHOD_initComponents0 = 0;
     
        // Method array 
        /*lazy MethodDescriptor*/
        private static MethodDescriptor[] getMdescriptor(){
            MethodDescriptor[] methods = new MethodDescriptor[1];
     
            try {
                methods[METHOD_initComponents0] = new MethodDescriptor(graphictools.lib.Cursor01.class.getMethod("initComponents", new Class[] {})); // NOI18N
                methods[METHOD_initComponents0].setDisplayName ( "" );
            }
            catch( Exception e) {}                       
     
        // Here you can add code for customizing the methods array.
     
            return methods;     }                  
     
        private static java.awt.Image iconColor16 = null;                    
        private static java.awt.Image iconColor32 = null;
        private static java.awt.Image iconMono16 = null;
        private static java.awt.Image iconMono32 = null;                  
        private static String iconNameC16 = "/graphictools/img/ico16.gif";                 
        private static String iconNameC32 = "/graphictools/img/ico32.gif";
        private static String iconNameM16 = "/graphictools/img/ico16.gif";
        private static String iconNameM32 = "/graphictools/img/ico32.gif";               
     
        private static final int defaultPropertyIndex = -1;               
        private static final int defaultEventIndex = -1;             
     
     
     
     
        // Here you can add code for customizing the Superclass BeanInfo.
     
     
     
        /**
         * Gets the bean's <code>BeanDescriptor</code>s.
         * 
         * @return BeanDescriptor describing the editable
         * properties of this bean.  May return null if the
         * information should be obtained by automatic analysis.
         */
        public BeanDescriptor getBeanDescriptor() {
    	return getBdescriptor();
        }
     
        /**
         * Gets the bean's <code>PropertyDescriptor</code>s.
         * 
         * @return An array of PropertyDescriptors describing the editable
         * properties supported by this bean.  May return null if the
         * information should be obtained by automatic analysis.
         * <p>
         * If a property is indexed, then its entry in the result array will
         * belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor.
         * A client of getPropertyDescriptors can use "instanceof" to check
         * if a given PropertyDescriptor is an IndexedPropertyDescriptor.
         */
        public PropertyDescriptor[] getPropertyDescriptors() {
    	return getPdescriptor();
        }
     
        /**
         * Gets the bean's <code>EventSetDescriptor</code>s.
         * 
         * @return  An array of EventSetDescriptors describing the kinds of 
         * events fired by this bean.  May return null if the information
         * should be obtained by automatic analysis.
         */
        public EventSetDescriptor[] getEventSetDescriptors() {
    	return getEdescriptor();
        }
     
        /**
         * Gets the bean's <code>MethodDescriptor</code>s.
         * 
         * @return  An array of MethodDescriptors describing the methods 
         * implemented by this bean.  May return null if the information
         * should be obtained by automatic analysis.
         */
        public MethodDescriptor[] getMethodDescriptors() {
    	return getMdescriptor();
        }
     
        /**
         * A bean may have a "default" property that is the property that will
         * mostly commonly be initially chosen for update by human's who are 
         * customizing the bean.
         * @return  Index of default property in the PropertyDescriptor array
         *          returned by getPropertyDescriptors.
         * <P>      Returns -1 if there is no default property.
         */
        public int getDefaultPropertyIndex() {
            return defaultPropertyIndex;
        }
     
        /**
         * A bean may have a "default" event that is the event that will
         * mostly commonly be used by human's when using the bean. 
         * @return Index of default event in the EventSetDescriptor array
         *          returned by getEventSetDescriptors.
         * <P>      Returns -1 if there is no default event.
         */
        public int getDefaultEventIndex() {
            return defaultEventIndex;
        }
     
        /**
         * This method returns an image object that can be used to
         * represent the bean in toolboxes, toolbars, etc.   Icon images
         * will typically be GIFs, but may in future include other formats.
         * <p>
         * Beans aren't required to provide icons and may return null from
         * this method.
         * <p>
         * There are four possible flavors of icons (16x16 color,
         * 32x32 color, 16x16 mono, 32x32 mono).  If a bean choses to only
         * support a single icon we recommend supporting 16x16 color.
         * <p>
         * We recommend that icons have a "transparent" background
         * so they can be rendered onto an existing background.
         *
         * @param  iconKind  The kind of icon requested.  This should be
         *    one of the constant values ICON_COLOR_16x16, ICON_COLOR_32x32, 
         *    ICON_MONO_16x16, or ICON_MONO_32x32.
         * @return  An image object representing the requested icon.  May
         *    return null if no suitable icon is available.
         */
        public java.awt.Image getIcon(int iconKind) {
            switch ( iconKind ) {
            case ICON_COLOR_16x16:
                if ( iconNameC16 == null )
                    return null;
                else {
                    if( iconColor16 == null )
                        iconColor16 = loadImage( iconNameC16 );
                    return iconColor16;
                }
            case ICON_COLOR_32x32:
                if ( iconNameC32 == null )
                    return null;
                else {
                    if( iconColor32 == null )
                        iconColor32 = loadImage( iconNameC32 );
                    return iconColor32;
                }
            case ICON_MONO_16x16:
                if ( iconNameM16 == null )
                    return null;
                else {
                    if( iconMono16 == null )
                        iconMono16 = loadImage( iconNameM16 );
                    return iconMono16;
                }
            case ICON_MONO_32x32:
                if ( iconNameM32 == null )
                    return null;
                else {
                    if( iconMono32 == null )
                        iconMono32 = loadImage( iconNameM32 );
                    return iconMono32;
                }
    	default: return null;
            }
        }
     
    }
    J'ai essayé avec des gif et des png... Merci d'avance pour votre aide...

  2. #2
    Membre confirmé
    Avatar de fabou3377
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2006
    Messages : 182
    Par défaut
    Bon ben pour finir j'ai trouvé mais qu'est-ce que c'étais tordu... Dans ma classe
    NewBean, il faut même si aucun champ ne le demande mettre dans l'import ces deux lignes:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    import java.beans.*;
    import java.io.Serializable;
    Donc si netbeans vous dit que ces en-têtes ne sont pas utilisées, NE LES ENLEVER PAS....

  3. #3
    Membre confirmé
    Avatar de fabou3377
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2006
    Messages : 182
    Par défaut
    Euh! ben Non! Il y a une condition supplémentaire! Si je créer un Javabeans component ceci fonctionne et mon icône s'affiche, l'inconvénient et que je n'ai pas de Form (partie visuelle) à disposition... Si je créer un bean form, je créer ma classe beaninfo et là je n'ai pas d'icône...

    Est-ce possible d'avoir un bean avec un form et un icône qui s'ajoute dans le palette manager?? Je ne demande quand pas grand chose ...Je sais ce n'est qu'un icône mais je suis maniac...

    A l'aide!! Merci d'avance...

  4. #4
    Rédacteur
    Avatar de eclesia
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    2 111
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 111
    Par défaut
    la reponse m'interesse aussi , je te rassure tu ne passe pas pour un maniac, c'est normal de vouloir avoir les petits icones, ca fait partie de la qualité du bean.

  5. #5
    Membre confirmé
    Avatar de fabou3377
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2006
    Messages : 182
    Par défaut
    Après un dur labeur j'ai trouvé pourquoi, mais j'aurai besoin de certaines explications... Soit lorsqu'on créer une classe de type bean form il y a automatiquement une méthode initcomponents() qui est créée par Netbeans pour la création des composants... Jusqu'ici tout est logique.. Pour que l'icône s'affiche il faut tout simplement créer un méthode xxxxBeanInfo.java (à l'aide de l'assistant par exemple) et mettre la coche getFromIntrospection sur la méthode initcomponents dans la classe xxxxxxBeanInfo.java dans la partie Designer....

    Puis clic droit sur le bean et add to palette...

    Et c'est là que j'ai besoin d'un grand esprit pour m'expliquer...Pourqouoi l'cône s'affiche-t-il lorsque j'active cette option??

  6. #6
    Membre éclairé

    Homme Profil pro
    Inscrit en
    Juillet 2006
    Messages
    766
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 766
    Par défaut
    Citation Envoyé par eclesia Voir le message
    la reponse m'interesse aussi , je te rassure tu ne passe pas pour un maniac, c'est normal de vouloir avoir les petits icones, ca fait partie de la qualité du bean.
    Vous êtes des maniacs dangereux !

    16x16, c'est petit, ca m'a pris une heure a faire un truc qui ressemble à quelque chose ! Dans le designeur du BeanInfo, il faut cliquer tout en haut pour pouvoir changer les propriétés des Icones.

  7. #7
    Membre éclairé

    Homme Profil pro
    Inscrit en
    Juillet 2006
    Messages
    766
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 766
    Par défaut
    Par contre je n'arrive pas à avoir un rendu normal dans le GUI Builder. J'ai un panel contenant deux panel, dont un rouge.
    L'autre panel contient des CheckBox.

    Au final, quand je depose mon Bean dans Matisse, je distingue bien le panel rouge, mais pas les Checkbox.
    Quand je run, tout va bien.

Discussions similaires

  1. Changer l'icône d'une fenêtre dans forms 10g DS
    Par rafioklou dans le forum Forms
    Réponses: 2
    Dernier message: 10/10/2007, 12h08
  2. Import de mes JavaBean dans mes pages jsp impossibles
    Par Shogun dans le forum Servlets/JSP
    Réponses: 11
    Dernier message: 23/02/2007, 16h21
  3. Ajouter une icône d'une application dans le barre des tâches
    Par Lorponos dans le forum Autres Logiciels
    Réponses: 11
    Dernier message: 13/05/2006, 20h41
  4. [VB6] Réduire en icône une MDI form dans le systray
    Par lefoimpeur dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 12/01/2006, 17h56

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