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 :

Afficher une JTable


Sujet :

Java

  1. #1
    Membre régulier Avatar de moomba
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 134
    Points : 104
    Points
    104
    Par défaut Afficher une JTable
    Bonjour

    Je suis débutant et je cherche à afficher une JTable dans un JScrollPane dans une JFrame. Mais cela ne veut pas fonctionner.

    Voici mon code (en raccourcis). Tampon_Donnees et Dim_j sont initialisés et ont leurs valeurs dans la procédure Lecture();

    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
     
    public class Papillon extends JFrame
    {
     
    	  JPanel contentPane;
    	  BorderLayout borderLayout1 = new BorderLayout();
    	  JMenuBar jMenuBar1 = new JMenuBar();
    	  JMenu jMenuFile = new JMenu();
    	  JMenuItem jMenuFileExit = new JMenuItem();
    	  JMenuItem jMenuFileNew = new JMenuItem();
    	  JScrollPane jScrollPane1;// = new JScrollPane();
    	  JPanel jPanel1 = new JPanel();
    	  JTable jTable1 = new JTable();
    	  JLabel essai = new JLabel("toto");
     
    	  String [][] Tampon_Donnees;
    	  String [] Titres = {"Type","Série","Tome","Titre","Auteurs","Editeur"} ;
    	  Object [][] Donnees;
     
    	  int Dim_j;
     
    	  public Papillon()
    	  {
    		    contentPane = (JPanel) getContentPane();
    		    contentPane.setLayout(borderLayout1);
    		    setSize(new Dimension(400, 300));
    		    setTitle("Papillon");
    		    jMenuFile.setText("Fichier");
    		    jMenuFileExit.setText("Quitter");
    		    jMenuFileNew.setText("Nouveau");
    		    jMenuBar1.add(jMenuFile);
    		    jMenuFile.add(jMenuFileExit);
    		    jMenuFile.add(jMenuFileNew);
     
    			Lecture();
     
    			Donnees = new Object [6][Dim_j];
     
    			for(int j=0;j<Dim_j;j++)
    			{
    				for(int i=0;i<6;i++)
    				{
    					Donnees [i][j]= Tampon_Donnees[i][j];
    				}
    			}
     
    			jTable1=new JTable(Donnees,Titres);
     
    		    jScrollPane1 = new JScrollPane(jTable1);
    		    contentPane.add(jScrollPane1, java.awt.BorderLayout.CENTER);
    		    jPanel1.add(essai);
    		    contentPane.add(jPanel1, java.awt.BorderLayout.EAST);
    		    setJMenuBar(jMenuBar1);
     
    		        setDefaultCloseOperation(EXIT_ON_CLOSE);
    			setVisible(true);		
     
    			jMenuFileNew.setEnabled(false);
     
    	  }
    Et la réponse de l'exécuteur (ça passe la compilation) vachement explicite (Unknow, Unknow...)

    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
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 4
    	at javax.swing.JTable$1.getValueAt(Unknown Source)
    	at javax.swing.JTable.getValueAt(Unknown Source)
    	at javax.swing.JTable.prepareRenderer(Unknown Source)
    	at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
    	at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
    	at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
    	at javax.swing.plaf.ComponentUI.update(Unknown Source)
    	at javax.swing.JComponent.paintComponent(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JViewport.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JLayeredPane.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
    	at javax.swing.RepaintManager.paint(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    	at java.awt.Container.paint(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 4
    	at javax.swing.JTable$1.getValueAt(Unknown Source)
    	at javax.swing.JTable.getValueAt(Unknown Source)
    	at javax.swing.JTable.prepareRenderer(Unknown Source)
    	at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
    	at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
    	at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
    	at javax.swing.plaf.ComponentUI.update(Unknown Source)
    	at javax.swing.JComponent.paintComponent(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JViewport.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at javax.swing.JLayeredPane.paint(Unknown Source)
    	at javax.swing.JComponent.paintChildren(Unknown Source)
    	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
    	at javax.swing.RepaintManager.paint(Unknown Source)
    	at javax.swing.JComponent.paint(Unknown Source)
    	at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    	at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    	at java.awt.Container.paint(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Voici donc mon problème.

    Quelqu'un aurait-il une idée ?
    "Celui qui à le pouvoir de faire le mal, mais qui ne le fait pas, celui là est le prince de l'univers." (shakespeare)

  2. #2
    Membre régulier Avatar de moomba
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 134
    Points : 104
    Points
    104
    Par défaut
    Problème résolu

    Il suffisait de ne pas utiliser une tableau d'objets pour le constructeur de la JTable, mais un tableau de strings. C'est bizarre puisque le constructeur avec des objets existe, mais il ne marche pas pour moi, j'ai vérifié le tableau et il était bon.

    Encore merci
    "Celui qui à le pouvoir de faire le mal, mais qui ne le fait pas, celui là est le prince de l'univers." (shakespeare)

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 10/12/2014, 18h21
  2. [Swing] Afficher une JTable speciale en java
    Par benssj5 dans le forum Composants
    Réponses: 6
    Dernier message: 12/03/2013, 20h21
  3. Afficher une JTable comprenant plusieurs tables SQL
    Par cedric774 dans le forum JDBC
    Réponses: 6
    Dernier message: 18/08/2010, 17h23
  4. Afficher une Jtable sur une JPanel
    Par moufasa dans le forum Débuter
    Réponses: 3
    Dernier message: 06/04/2009, 16h39
  5. [JTable] Afficher une date dans un tableau / Renderer
    Par isak dans le forum Composants
    Réponses: 3
    Dernier message: 11/07/2005, 17h09

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