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 :

Ma JTable ne se trie pas


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

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

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut Ma JTable ne se trie pas
    Bonjour, je rencontre un nouveau problème. Cela concerne mes JTable. J'y affecte un rowsorter mais lorsque je clique sur les entètes, les lignes ne se triens pas alors que le petit triangle qui indique l'ordre s'affiche. En gros aucun ne se fait, comme si toutes les valeurs étaient toutes égales.

    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
     
    public class Table extends JTable {
     
        private TableModel model;
        private TableRowSorter<TableModel> sorter;
        private ArrayList<RowSorter.SortKey> listSorter;
     
     
        public Table (String[] titles, ResultSet resultSet, int minimumRowCount) {
            super();
            model = new TableModel(titles, resultSet, minimumRowCount);
            setModel(model);
     
            listSorter = new ArrayList<RowSorter.SortKey>();
            sorter = new TableRowSorter<TableModel>(model);
            listSorter.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
            try {sorter.setSortKeys(listSorter);}
            catch(IllegalArgumentException ex ){ex.printStackTrace();}
     
            try {setRowSorter(sorter);}
            catch (IllegalArgumentException iae){iae.printStackTrace();}
            listSorter.clear();
        }
    }
    Le modèle si venait de là

    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
     
    public class TableModel extends AbstractTableModel {
     
        private String[] titles;
        private ResultSet resultSet;
     
        private int minimumRowCount;//number of minimum shown rows. If data is not big enouth,
                        //complet table with null value
        private int maximumRowCount;//number of maximum rows displayed.
                        //Include shown ans hidden rows
     
     
        public TableModel() {
        }
     
     
        public TableModel(String[] titles, ResultSet resultSet, int minimumRowCount){
            this.titles = titles;
            this.resultSet = resultSet;
            try {
                resultSet.last();
                maximumRowCount = resultSet.getRow();
                resultSet.beforeFirst();
            }
            catch (SQLException sql) {
                currentRowCount = minimumRowCount;
            }
        }
     
        /**
         * 
         * @return the number of columns in the model
         * Returns the number of columns in the model.
         * A Table uses this method to determine how many columns it should create
         * and display by default.
         */
        public int getColumnCount() {
            return titles.length;
        }
     
        /**
         *
         * @return the number of rows in the model
         * Returns the number of rows in the model. A JTable uses this method to
         * determine how many rows it should display. This method should be quick,
         * as it is called frequently during rendering.
         */
        public int getRowCount() {
            return currentRowCount;
        }
     
        /**
         * 
         * @param parm1 the row whose value is to be queried
         * @param parm2 the collumn whose value is to be queried
         */
        public Object getValueAt(int parm1, int parm2) {
            try {
                resultSet.absolute(parm1+1);
                return resultSet.getString(parm2+1);
            }
            catch(SQLException sql){sql.printStackTrace();return null;}
        }
     
        /**
         *
         * @param col
         */
        public String getColumnName(int col) {
            return titles[col];
        }
     
        /**
         *
         * @param rowIndex
         * @param columnIndex
         */
        public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
        }
     
     
        public void setMinimumRowCount(int minimumRowCount) {
            this.minimumRowCount = minimumRowCount;
        }
     
    }
    Merci d'avance

  2. #2
    Membre chevronné Avatar de javaNavCha
    Homme Profil pro
    EKG Group
    Inscrit en
    Juillet 2009
    Messages
    311
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

    Informations professionnelles :
    Activité : EKG Group
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2009
    Messages : 311
    Par défaut
    Salut...
    bon je vois que jtable.repaint(); actualise le contenu de ton JTable..

  3. #3
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

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

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    J'ai essayé et ça n'a rien donnée

  4. #4
    Membre émérite Avatar de fraco
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    750
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2006
    Messages : 750
    Par défaut
    lorsque je clique sur les entêtes, les lignes ne se triens pas
    dans swingx il y a un JXTable avec le tri incorporé : il n'y a qu'à cliquer sur un entête de colonne.... très pratique !

  5. #5
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

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

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    J'ai entendu parler de cette classe. Est-ce qu'il y a possibilité de désactiver le tri ? Il peut y avoir des cas avec un contenu énorme (j'ai d'ailleurs poster un topic à ce sujet), et il ne faudrait pas trier à partir d'un certain nombre de lignes.

  6. #6
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

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

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    J'ai trouvé, setAutoRowSorter(boolean b);

    Pour le moment, j'ai une NPE de levée :

    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
     
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at org.jdesktop.swingx.JXTable.updateStringValueRegistryColumnClasses(JXTable.java:3411)
            at org.jdesktop.swingx.JXTable.tableChanged(JXTable.java:1535)
            at javax.swing.JTable.setModel(JTable.java:3625)
            at org.jdesktop.swingx.JXTable.setModel(JXTable.java:1609)
            at graphics.table.Table.setModel(Table.java:93)
            at javax.swing.JTable.<init>(JTable.java:611)
            at javax.swing.JTable.<init>(JTable.java:539)
            at org.jdesktop.swingx.JXTable.<init>(JXTable.java:509)
            at graphics.table.Table.<init>(Table.java:29)
            at graphics.table.Table.<init>(Table.java:43)
            at frames.customerMenu.view.SelectCustomerView.componentsBuilder(SelectCustomerView.java:42)
            at frames.AbstractView.<init>(AbstractView.java:70)
            at frames.customerMenu.view.SelectCustomerView.<init>(SelectCustomerView.java:27)
            at frames.customerMenu.frame.SelectCustomerFrame.launch(SelectCustomerFrame.java:22)
            at functionality.AbstractFunctionality.openFrame(AbstractFunctionality.java:22)
            at graphics.MenuItem.actionPerformed(MenuItem.java:20)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
            at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1216)
            at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1257)
            at java.awt.Component.processMouseEvent(Component.java:6038)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5803)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4410)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2429)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Discussions similaires

  1. le Sorting du GridView qui trie pas
    Par zooffy dans le forum ASP.NET
    Réponses: 2
    Dernier message: 15/07/2008, 16h47
  2. [JTable] Je n'arrive pas à la vider
    Par rock in the air dans le forum Composants
    Réponses: 13
    Dernier message: 12/05/2008, 15h08
  3. Titres des colonnes d'une JTable ne s'affiche pas.
    Par maxlegrand dans le forum Composants
    Réponses: 2
    Dernier message: 05/06/2007, 23h24
  4. Réponses: 1
    Dernier message: 02/12/2004, 11h51
  5. [JTable] [JTableHeader] Ne correspondent pas
    Par thomas_strass dans le forum Composants
    Réponses: 2
    Dernier message: 14/06/2004, 16h15

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