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 :

Deux instance de jtreetable


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Avril 2007
    Messages
    360
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 360
    Par défaut Deux instance de jtreetable
    bonjour,
    je travail avec les jtreetable :
    j'ai instancié mon modele et j'affiche les deux jtreetable dans une meme maquette sur 2 jpanel aucun probleme juska maintenant,

    mais j'ai ecri la fonction mousePressed je veux connaitre l'objet selectionné lorsque l'evenement est generé voila 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 void mousePressed(MouseEvent e) {
           Libelle="";
           if(e.getSource()instanceof JTreeTable) { 
             // mTreeTablePanelSource : premier jtreetable
                if(mTreeTablePanelSource.getFocusTraversalKeysEnabled()==true){
                    JOptionPane.showMessageDialog(null,"source :"+mTreeTablePanelSource.getFocusTraversalKeysEnabled());
                    int ligne=mTreeTablePanelSource.mTreeTable.getSelectedRow();
                    if (ligne != -1) {
                      if(mTreeTablePanelSource.mTreeTable.getTree().isCollapsed(ligne)){
                         mTreeTablePanelSource.mTreeTable.getTree().expandRow(ligne);
                      } 
                      TreePath path = mTreeTablePanelSource.mTreeTable.getTree().getPathForRow(ligne);
                      Node node = (Node)path.getLastPathComponent();
                      Libelle=node.getLibelle();
                      JOptionPane.showMessageDialog(null,"source"+Libelle);
                    }  
                }
              else{
                   //mTreeTablePanelDestination : 2 eme Jtreetable
                    if(mTreeTablePanelDestination.getFocusTraversalKeysEnabled()==true){
                        JOptionPane.showMessageDialog(null,"destination :"+getFocusTraversalKeysEnabled());
                            int ligne=mTreeTablePanelDestination.mTreeTable.getSelectedRow();
                            if (ligne != -1) {
                              if(mTreeTablePanelDestination.mTreeTable.getTree().isCollapsed(ligne)){
                                 mTreeTablePanelDestination.mTreeTable.getTree().expandRow(ligne);
                              } 
                              TreePath path = mTreeTablePanelDestination.mTreeTable.getTree().getPathForRow(ligne);
                              Node node = (Node)path.getLastPathComponent();
                              Libelle=node.getLibelle();
                              JOptionPane.showMessageDialog(null,"source"+Libelle);
                            }                   
                    }
                }
           }
        }

    connaitre l'objet (1 ou 2) selon celui pressé

    toujours il passe par le premier meme si je ne clique (pressed) pas sur le 2eme
    Merci si je suis pas claire Merci de le signalé

  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
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    if(e.getSource()==monTreeTable1) {....}
    else if (e.getSource()==monTreeTable2) {....}
    Note, çà suppose que dans l'object implémentant MouseEvent, tu aie accès aux variable monTreeTable1 et monTreeTable2.

  3. #3
    Membre éclairé
    Inscrit en
    Avril 2007
    Messages
    360
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 360
    Par défaut
    mon evenement est appliqué sur tous mon panel
    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
    public class PanelCBTransformation extends JPanel implements MouseListener{
    ....
     
        private TreeTablePanel mTreeTablePanelSource=null;
        private TreeTablePanel mTreeTablePanelDestination=null;
    ....
     
     
        public void mousePressed(MouseEvent e) {
           LibelleSource="";
           if(e.getSource()instanceof JTreeTable) { 
                if(e.getSource()==mTreeTablePanelSource){
                    JOptionPane.showMessageDialog(null,"source :"+mTreeTablePanelSource.getFocusTraversalKeysEnabled());
                    int ligne=mTreeTablePanelSource.mTreeTable.getSelectedRow();
                    if (ligne != -1) {
                      if(mTreeTablePanelSource.mTreeTable.getTree().isCollapsed(ligne)){
                         mTreeTablePanelSource.mTreeTable.getTree().expandRow(ligne);
                      } 
                      TreePath path = mTreeTablePanelSource.mTreeTable.getTree().getPathForRow(ligne);
                      Node node = (Node)path.getLastPathComponent();
                      LibelleSource=node.getLibelle();
                      JOptionPane.showMessageDialog(null,"source"+LibelleSource);
                    }  
                }
              else{
                    if(e.getSource()==mTreeTablePanelDestination){
                        JOptionPane.showMessageDialog(null,"destination :"+getFocusTraversalKeysEnabled());
                            int ligne=mTreeTablePanelDestination.mTreeTable.getSelectedRow();
                            if (ligne != -1) {
                              if(mTreeTablePanelDestination.mTreeTable.getTree().isCollapsed(ligne)){
                                 mTreeTablePanelDestination.mTreeTable.getTree().expandRow(ligne);
                              } 
                              TreePath path = mTreeTablePanelDestination.mTreeTable.getTree().getPathForRow(ligne);
                              Node node = (Node)path.getLastPathComponent();
                              LibelleSource=node.getLibelle();
                              JOptionPane.showMessageDialog(null,"source"+LibelleSource);
                            }                   
                    }
                }
           }
        }
     
    }
    j'ai testé mais aucune resulat pour l'instant?
    Merci de bien m'expliqué comment???

  4. #4
    Membre éclairé
    Inscrit en
    Avril 2007
    Messages
    360
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 360
    Par défaut

    Merci pour votre aide, Mon probleme est résolu en ajoutant un listener sur chaque objet : voila le code de premier et le meme pour le deuxieme
    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
            mTreeTablePanelSource.mTreeTable.addMouseListener(new MouseAdapter(){
                public void mouseReleased(MouseEvent e){
                    if(e.getSource()instanceof JTreeTable) { 
                             JOptionPane.showMessageDialog(null,"source :"+mTreeTablePanelSource.getFocusTraversalKeysEnabled());
                             int ligne=mTreeTablePanelSource.mTreeTable.getSelectedRow();
                             if (ligne != -1) {
                               if(mTreeTablePanelSource.mTreeTable.getTree().isCollapsed(ligne)){
                                  mTreeTablePanelSource.mTreeTable.getTree().expandRow(ligne);
                               } 
                               LibelleSource="";
                               TreePath path = mTreeTablePanelSource.mTreeTable.getTree().getPathForRow(ligne);
                               Node node = (Node)path.getLastPathComponent();
                               LibelleSource=node.getLibelle();
                               JOptionPane.showMessageDialog(null,"source"+LibelleSource);
                             }  
                       }
                }
            });
    Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment Stop deux instances de Jonas sur la même machine
    Par rachidBahja dans le forum JOnAS
    Réponses: 1
    Dernier message: 27/10/2006, 15h13
  2. lancer deux instance apache
    Par draiah dans le forum Apache
    Réponses: 4
    Dernier message: 10/10/2006, 18h14
  3. Réponses: 2
    Dernier message: 09/06/2006, 19h34
  4. [oracle 8i] requete SQL entre deux instances oracle
    Par flore_ange dans le forum Oracle
    Réponses: 5
    Dernier message: 18/04/2006, 17h43
  5. [Conception] Deux instances de l'application
    Par masto dans le forum Général Java
    Réponses: 18
    Dernier message: 03/08/2004, 18h00

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