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 :

Jtable multiple question.


Sujet :

Composants Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Février 2005
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 9
    Points : 9
    Points
    9
    Par défaut Jtable multiple question.
    Bonjour,

    j'ai plusieurs petite question sur les jtable.

    est il possible de rajouter une ligne à la fin de sont jtable pour l'insertion?
    comment insérer une liste déroulante (sachant que les données sont prise dans un base de données)?
    comment faire pour supprimer une ligne entière?

    mon table modèle :

    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
     
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
     
     
    import javax.swing.table.AbstractTableModel;
     
    public class JtablePeriode extends AbstractTableModel 
    {
    	private static final long serialVersionUID = 0;
     
    	private String[] columnNames = {"ID","Classe", "Nom semestre", "Date début", "Date fin"};
    	private Object[][] data;
    	public int getColumnCount() {return columnNames.length;}
    	public int getRowCount() {return data.length;}
    	public int getSelectedRow() {
    		return 0;
    	}
    	public String getColumnName(int col) {return columnNames[col];}
    	public Object getValueAt(int row, int col) {return data[row][col];}
    	public Class getColumnClass(int c) {return getValueAt(0,c).getClass();}
    	public boolean setRowSelectionAllowed(boolean rowSelectionAllowed)
    	{
    		return true;
    	}
    	public boolean isCellEditable(int row, int col) {
            if ( col==0 ) {
                return ( false );
        } else {
                return ( true );
        } 
    	}
    	public void setValueAt(Object value, int row, int col) 
    	{
    		data[row][col] = value;
    		fireTableCellUpdated(row,col);
    	}	
    	public JtablePeriode() {
    		ArrayList test = TablePeriode.selectDonnees();
    		int j = 0;
    		this.data = new Object[test.size()][5];
    		for (int i=0;i<test.size();i++) {
    			TablePeriode per = (TablePeriode) test.get(i);
    			this.data[j] = new Object[5];
    			this.data[j][0] = per.idToString(); // révupère l'id de la table periode
    			this.data[j][1] = per.fkClasseToString(); // la fk -> pk de la table classe
    			this.data[j][2] = per.getNomPeriode();
    			this.data[j][3] = per.getDebutPeriode();
    			this.data[j][4] = per.getFinPeriode();
    			j++;
    		}
    	}
    	// update des champs de la table periode
    	public void fireTableCellUpdated(int row, int column) {
     
    		java.sql.Connection connection = DataBase.getConnection();		
    		try
    		{	
    			Statement statementUpdate = connection.createStatement ();
     
    			switch(column)
    			{
    			case 1:	String update0 = "UPDATE periode SET fkclasse = '"+ this.data[row][column] +"' where pkperiode ='"+this.data[row][0]+"'";
    					statementUpdate.execute (update0);
    					break;
    			case 2:	String update1 = "UPDATE periode SET nomperiode = '"+ this.data[row][column] +"'where pkperiode ='"+this.data[row][0]+"'";
    					statementUpdate.execute (update1);System.out.println(column);
    					break;
    			case 3:	String update2 = "UPDATE periode SET datedebutperiode = '"+ this.data[row][column] +"'where pkperiode ='"+this.data[row][0]+"'";
    					statementUpdate.execute (update2);System.out.println(column);
    					break;
    			case 4:	String update3 = "UPDATE periode SET datefinperiode = '"+ this.data[row][column] +"'where pkperiode ='"+this.data[row][0]+"'";
    					statementUpdate.execute (update3);System.out.println(column);
    					break;
    			default:System.out.println("ERREUR");
    			}
    			statementUpdate.execute ("COMMIT;");	
    			statementUpdate.close ();
    		}
    		catch (SQLException exception)
    		{
    			exception.printStackTrace ();
    		}
    	}
    }

  2. #2
    Membre éprouvé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2007
    Messages
    697
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Janvier 2007
    Messages : 697
    Points : 1 241
    Points
    1 241
    Par défaut
    Salut,
    pour les questions 1 & 3 voir la javadoc de JTable sinon pour la 2, là je vois pas...

  3. #3
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Pour la question 2 direction le tuto de sun: How to use tables

Discussions similaires

  1. Multiples questions sur l'affichage
    Par Array dans le forum Windows
    Réponses: 0
    Dernier message: 30/04/2009, 02h48
  2. Multiples questions relatives au CSS
    Par Daddy91 dans le forum Mise en page CSS
    Réponses: 6
    Dernier message: 22/08/2007, 15h16
  3. [premiers pas] multiples questions
    Par eclesia dans le forum Maven
    Réponses: 1
    Dernier message: 13/07/2007, 11h14
  4. [UBUNTU] multiple question , son, internet, flash
    Par eclesia dans le forum Ubuntu
    Réponses: 2
    Dernier message: 28/05/2007, 20h19
  5. Personnages 3D [Multiple questions]
    Par Ezarion dans le forum Développement 2D, 3D et Jeux
    Réponses: 7
    Dernier message: 28/12/2006, 20h59

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