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

 Java Discussion :

JTree Drag n Drop


Sujet :

Java

  1. #1
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut JTree Drag n Drop
    Bonsoir,

    Je cherche a réaliser un drag n drop depuis un JTree vers un JTable j'ai donc utiliser un TransfertHandler sur mon JTable ca fonctionne bien mais lorsque je récupère le nœud de mon JTree ca affiche un objet comme ceci :



    et donc je veut récupérer le nom du nœud merci d'avance

  2. #2
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Tu peux nous montrer comment tu remplis la table? Tu as plusieurs possiblités suivant la manière dont c'est fait.

  3. #3
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut Ma class myTransfertHandler
    Salut tchize voici ma class myTransfertHandler :

    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
     
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    import javax.swing.JComponent;
    import javax.swing.JTable;
    import javax.swing.TransferHandler;
    import javax.swing.table.DefaultTableModel;
     
    /**
     *
     * @author microsoft1
     */
    public class MyTransfetHandler extends TransferHandler{
     
      private final JTable _table;
      private final String _st1, _st2;
     
      public MyTransfetHandler(JTable tb){
        this._table = tb;
        this._st1   = "en attente";
        this._st2   = "en attente";
      }
     
      @Override
      public int getSourceActions(JComponent c) {
        return COPY_OR_MOVE;
      }
     
      @Override
      public boolean canImport(JComponent c, DataFlavor[] d) {
        for(int i = 0; i < d.length; i++) return d[i].equals(DataFlavor.stringFlavor);
        return false;
      }
     
      @Override
      public boolean importData(TransferSupport support){
         JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();
         int row = dl.getRow();
         String data;
         try {
            data = (String)support.getTransferable().getTransferData(DataFlavor.stringFlavor);
         } catch (UnsupportedFlavorException | IOException e) {
           return false;
         }
         DefaultTableModel model = (DefaultTableModel)this._table.getModel();
         model.addRow(new String[]{data, this._st1, this._st2});
     
         return true;
      }
     
     
     
     
    }
    au niveau de la méthode importData je récupère le modèle de mon JTable par défaut et ensuite j'ajoute ma ligne

  4. #4
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    ok, ben c'est au moment où dans ton JTree tu fais le StartDrag que tu met n'importe quoi dans le StringFlavor (objct.toString()) au lieu de mettre le nom. Tu peux montre l'autre coté du transfert?

  5. #5
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut Start Drag
    Qu'entend tu par startDrag actuellement je fait juste ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     this._tree.setDragEnabled(true);

  6. #6
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    ha tu laisse le JTree tout faire. Dans ce cas, regarde dans le Flavor proposées par le JTree lors du drop si tu n'a pas possibilité de récupérer l'objet plutôt qu'un String

  7. #7
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut
    Oui c'est justement ça que j'avais dabord essaye de faire sans succès du coup si tu peux m'orienter vers une autre méthode ce serait sympa

  8. #8
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Je ne connais pas trop le comportement du JTree, tu peux faire un listing de tous les Flavors qui te sont proposés? Il devrait y avoir un SerializedObjectFlavor ou quelque chose du genre.

  9. #9
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut
    il y a juste ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataFlavor.javaSerializedObjectMimeType

  10. #10
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Modifie cette méthode et donne nous sa sortie, je ne demande pas ce qui est définis dans l'API de DataFlavor, ça je peux le lire aussi


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
      @Override
      public boolean canimport(JComponent c, DataFlavor[] d) {
        for (DataFlavor df: d){
           System.out.println("Available flavor: "+df.getMimeType()+ "# "+df.getSubType() + "#"+df.getHumanPresentableName() );
        }
        for(int i = 0; i < d.length; i++) return d[i].equals(DataFlavor.stringFlavor);
        return false;
      }

  11. #11
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut
    Voila le résultat pour un seul nœud.

    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
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String
    Available flavor: text/html; class=java.lang.String# html#text/html
    Available flavor: text/html; class=java.io.Reader# html#text/html
    Available flavor: text/html; class=java.io.InputStream; charset=unicode# html#text/html
    Available flavor: text/plain; class=java.lang.String# plain#text/plain
    Available flavor: text/plain; class=java.io.Reader# plain#text/plain
    Available flavor: text/plain; class=java.io.InputStream; charset=unicode# plain#text/plain
    Available flavor: application/x-java-jvm-local-objectref; class=java.lang.String# x-java-jvm-local-objectref#application/x-java-jvm-local-objectref
    Available flavor: application/x-java-serialized-object; class=java.lang.String# x-java-serialized-object#Unicode String

  12. #12
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    ok, il propose que du String :/

    On peux voir comment tu a peuplé ton JTree?
    view.Arbo, c'est quelle classe ?

    Tu dois aussi surcharger la méthode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    protected Transferable createTransferable(JComponent c)
    dans ton TransfertHandler
    un truc du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        protected Transferable createTransferable(JComponent c) {
            JTree tree = (JTree)c;
            TreePath path = tree.getSelectionPath();
            File f = (File)path.getLastPathComponent();
     
                return new TonTransferable(f);
        }

  13. #13
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut
    j'ai utilisé comme base ce code la : http://www.pushing-pixels.org/wp-con...etreepanel.txt pour remplir mon JTree je me demande du coup si je ne doit pas créer mon transfertHandler pour le JTree mais alors qu'elle méthode redéfinir ?

  14. #14
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut
    Bonsoir,

    Je réexplique mon objectif je souhaite réalisé un drag n drop depuis un JTree vers un JTable le souci c'est que lorsque j'active le drag avec setDragEnabled sur mon JTree et que je "drag" un nœud lors du drop sur mon JTable je ne récupére que l'adresse de mon objet (tree.Arbo@6ceeaa27), sous forme de String (donc plus possible de manipuler l'objet) est-ce que quelqu’un aurait le gentillesse de me proposer une solution concrète merci d'avance ca fait un moment que je galère la dessus

  15. #15
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Je te l'ai dit, tu doit créer ton propre transfert Handler, qui contiendra un File (ou autre chose) plutot que du texte. Le comportement par défaut semble être pour jtree de faire un toString sur le node.

  16. #16
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Par défaut
    re oui j'ai voulu le faire mais quel est la méthode a redéfinir car lorsque je crée mon TransfertHandler le drag ne fonctionne plus voila ce que javai commencer a tester :
    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
     
    public class MyTransfertHandlerTree extends TransferHandler {
     
      @Override
      public boolean importData(JComponent c, Transferable tr) {
        try {
          Object treeNode = tr.getTransferData(DataFlavor.stringFlavor);
          System.out.println(treeNode);
        } catch (Exception e) {
          //
        }
        return true;
      }
     
      @Override
      protected Transferable createTransferable(JComponent c) {
        JTree tree = (JTree) c;
        final TreePath path = tree.getSelectionPath();
        System.out.println(path);
        return new TransferableTreeNode(path);
      }
     
      class TransferableTreeNode implements Transferable {
     
        public DataFlavor TREE_PATH_FLAVOR = new DataFlavor(TreePath.class,
          "Tree Path");
     
        DataFlavor flavors[] = {TREE_PATH_FLAVOR};
     
        TreePath path;
     
        public TransferableTreeNode(TreePath tp) {
          path = tp;
        }
     
        public synchronized DataFlavor[] getTransferDataFlavors() {
          return flavors;
        }
     
        public boolean isDataFlavorSupported(DataFlavor flavor) {
          return (flavor.getRepresentationClass() == TreePath.class);
        }
     
        public synchronized Object getTransferData(DataFlavor flavor)
          throws UnsupportedFlavorException, IOException {
          if (isDataFlavorSupported(flavor)) {
            return (Object) path;
          } else {
            throw new UnsupportedFlavorException(flavor);
          }
        }
      }
     
    }

Discussions similaires

  1. (jlist,jtree) drag and drop entre 2 jlist vers un jtree
    Par olivier57b dans le forum Composants
    Réponses: 0
    Dernier message: 17/04/2012, 16h20
  2. [JTREE] drag & drop
    Par dinver dans le forum Composants
    Réponses: 4
    Dernier message: 01/02/2007, 15h03
  3. Drag and Drop sur une JTree
    Par Xhéras dans le forum Composants
    Réponses: 5
    Dernier message: 07/07/2006, 12h09
  4. [JTree] Drag and drop
    Par tomca dans le forum Composants
    Réponses: 7
    Dernier message: 01/12/2005, 09h03
  5. Drag and drop sur un JTree
    Par tomca dans le forum Composants
    Réponses: 4
    Dernier message: 02/08/2005, 10h54

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