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

Composants Java Discussion :

double clic JTable


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Artisan
    Inscrit en
    Février 2013
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Artisan
    Secteur : Bâtiment

    Informations forums :
    Inscription : Février 2013
    Messages : 23
    Par défaut double clic JTable
    Bonjour a tous,

    Je suis a essayer de créer une petite application de gestion d'article.
    J'ai des données dans une BD Mysql.
    Je les envoie dans une JTable.
    Pour l'instant tout marche bien.
    Mais je souhaiterai, en faisant un double-clic sur un des ouvrages ouvrir une fenêtre et afficher les détail de cet article mais lorsque que je double clic, il ne se passe rien.
    Est ce une erreur de l'endroit où j'ai déclarer le double clic ou une procédure spéciale a réaliser?
    Merci pour vos réponses.
    Cdl.
    Olivier

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Août 2010
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 30
    Par défaut
    Citation Envoyé par ol85000 Voir le message
    Bonjour a tous,

    Je suis a essayer de créer une petite application de gestion d'article.
    J'ai des données dans une BD Mysql.
    Je les envoie dans une JTable.
    Pour l'instant tout marche bien.
    Mais je souhaiterai, en faisant un double-clic sur un des ouvrages ouvrir une fenêtre et afficher les détail de cet article mais lorsque que je double clic, il ne se passe rien.
    Est ce une erreur de l'endroit où j'ai déclarer le double clic ou une procédure spéciale a réaliser?
    Merci pour vos réponses.
    Cdl.
    Olivier
    Bonjour,

    Voici un exemple de code qui permet le double clic :
    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
    /*
     * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     *   - Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     *   - Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     *   - Neither the name of Oracle or the names of its
     *     contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
     
    /*
     * SimpleTableDemo.java requires no other files.
     */
     
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableModel;
     
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
     
     
    public class SimpleTableDemo extends JPanel {
        private boolean DEBUG = true;
     
        public SimpleTableDemo() {
            super(new GridLayout(1,0));
     
            String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
     
            Object[][] data = {
            {"Kathy", "Smith",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"John", "Doe",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Sue", "Black",
             "Knitting", new Integer(2), new Boolean(false)},
            {"Jane", "White",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Joe", "Brown",
             "Pool", new Integer(10), new Boolean(false)}
            };
     
            TableModel ss = new DefaultTableModel(data, columnNames) {
                @Override
                public boolean isCellEditable(int row, int column) {
                   return false;
                }
            };
            final JTable table = new JTable(ss);
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setFillsViewportHeight(true);
     
            if (DEBUG) {
                table.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        printDebugData(table);
                        if(e.getClickCount() == 2) {
                        	JOptionPane.showMessageDialog(null, "Message Dialog");
                        }
                    }
                });
            }
     
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
     
            //Add the scroll pane to this panel.
            add(scrollPane);
        }
     
        private void printDebugData(JTable table) {
            int numRows = table.getRowCount();
            int numCols = table.getColumnCount();
            javax.swing.table.TableModel model = table.getModel();
     
            System.out.println("Value of data: ");
            for (int i=0; i < numRows; i++) {
                System.out.print("    row " + i + ":");
                for (int j=0; j < numCols; j++) {
                    System.out.print("  " + model.getValueAt(i, j));
                }
                System.out.println();
            }
            System.out.println("--------------------------");
        }
     
        /**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("SimpleTableDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            //Create and set up the content pane.
            SimpleTableDemo newContentPane = new SimpleTableDemo();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
     
            //Display the window.
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
     
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    }
    Et le lien vers le tutoriel Oracle : http://docs.oracle.com/javase/tutori...nts/table.html

  3. #3
    Membre averti
    Homme Profil pro
    Artisan
    Inscrit en
    Février 2013
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Artisan
    Secteur : Bâtiment

    Informations forums :
    Inscription : Février 2013
    Messages : 23
    Par défaut merci
    je te remercie Staithes.

    je regarde demain ce que tu m'as mis et ton lien.
    cdl.
    Olivier

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

Discussions similaires

  1. [JTable] Détecter double-clic + clic droit
    Par nicou_doude dans le forum Composants
    Réponses: 6
    Dernier message: 30/04/2008, 11h51
  2. Simuler un double-clic ou un F2 sur une JTable
    Par JamesP dans le forum Composants
    Réponses: 2
    Dernier message: 16/05/2007, 10h38
  3. [JTable] Détection de simple clic et de double clic
    Par Core8 dans le forum Composants
    Réponses: 7
    Dernier message: 22/12/2006, 13h44
  4. écoute de touches, de double clics sur un JTable
    Par Nicool dans le forum Composants
    Réponses: 7
    Dernier message: 06/06/2006, 12h52
  5. [JTable] gérer le double clic
    Par niko8181 dans le forum Composants
    Réponses: 4
    Dernier message: 02/06/2005, 15h57

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