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 :

Afficher un tableau de int[][] dans une JList


Sujet :

Composants Java

  1. #1
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut Afficher un tableau de int[][] dans une JList
    Bonjour à tous ,pourriez-vous m'aidez je souhaiterais afficher un tableau à deux dimenssions dans une jlist pour faire un tableau d'amortissement ma jlist s' appelle liste,voici ma fonction :

    Code JAVA : 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
    public void envoie_donnee(int Somme,int Date,int annee,int duree,int taux) {
    		// TODO Auto-generated method stub
    		// Appel du stateless bean
            AmortissementRemote Amortissement;
    		try {
    			Amortissement = lookupRemoteStatelessAmortissement();
             int[][] tableauAmortissement = Amortissement.calculerAmortissement(Somme, Date, annee, duree, taux);
     
     
     
     
     
     
     
     
     
     
     
     
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    	}

    voici comment est initialisé mon tableau dans une autres classe :

    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    tableauAmortissement [i][0] = moisPeriode;
    			tableauAmortissement [i][1] = anneePeriode;
    			tableauAmortissement [i][2] = mensualiteConstante;
    			tableauAmortissement [i][3] = amortissementPeriode;
    			tableauAmortissement [i][4] = interetsPeriode;

    Merci à vous n'hésiter pas si je n'ai pas était clair Bonne journée .

  2. #2
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 075
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 075
    Points : 7 980
    Points
    7 980
    Par défaut
    Bonjour,

    J'espère que tu te rends compte qu'un tableau a 2 dimension et une liste 1 seul ? (A moins de "concaténer" un des dimension pour la faire rentrer dans la jList, ce qui est possible aussi).
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Merci de votre réponse, donc que me conseillez vous de faire la concaténation ou je dois afficher dans autre chose qu'un jlist?

  4. #4
    Membre confirmé Avatar de Satch
    Homme Profil pro
    Hypnothérapeute - Magicien
    Inscrit en
    Mars 2004
    Messages
    498
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Suisse

    Informations professionnelles :
    Activité : Hypnothérapeute - Magicien

    Informations forums :
    Inscription : Mars 2004
    Messages : 498
    Points : 645
    Points
    645
    Par défaut
    un JTable ?
    Je sais que désormais vivre est un calembour,
    La mort est devenue un état permanent,
    Le monde est aux fantômes, aux hyènes et aux vautours.
    Moi je vous dis bravo et vive la mort.

  5. #5
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Il représente quoi ce tableau à deux dimensions? A priori un JTable fera l'affaire, mais tout dépend de ce que tu veux afficher. Ca peut aussi être un JTree qu'il te faut, pour avoir une liste à deux étages.

  6. #6
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Mais le problème avec le jtable c'est qu'après dans mon application je veux pouvoir afficher plusieurs tableaux à la suite ,peut-on faire sa ,en effet avec la jliste quand on affiche les éléments qu'importe le nombre est-ce que c'est le même principe?

  7. #7
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    ben oui, c'est un peu le principe du jtable, afficher des lignes et des colonnes

  8. #8
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Voici mon code :

    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     Object[][] donnee = Amortissement.calculerAmortissement(Somme, Date, annee, duree, taux);
             String[] entetes = {"mois", "annee", "mensualite", "amortissement", "interet"};
            JTable table = new JTable( donnee,entetes);
     		table.setBounds(116, 240, 277, 60);
     		getContentPane().add(table);

    seul problème que voici :

    Nom : amort.PNG
Affichages : 639
Taille : 22,4 Ko

    on ne voit pas tous le tableau j'aimerais toute afficher quelque soit la taille seriez-vous comment faire?

  9. #9
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    N'utilise pas setBounds, pour commencer, utilise un Layout.

    Ensuite, tu met ta JTable dans un JScrollPane et c'est réglé.

  10. #10
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Merci ,mais quand je fais un layout sa ne marche pas rien ne s'affiche j'ai testé plusieurs choses voilà mon code :

    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Object[][] donnee = Amortissement.calculerAmortissement(Somme, Date, annee, duree, taux);
             String[] entetes = {"mois", "annee", "mensualite", "amortissement", "interet"};
            JTable table = new JTable( donnee,entetes);
            table.size();
     	//	table.setBounds(116, 240, 300,300);
            getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH);

    j'ai essayer de changer le south en center mais rien ni fait je n'ai aucune erreur mais rien ne s'affiche.

  11. #11
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu peux montrer le reste de ton code? Tu as mis quel LayoutManager dans ton contentpane?

  12. #12
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Voici mon code :

    Code JAVA : 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
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    package client;
     
    import hw.AmortissementAvecEtatRemote;
    import hw.AmortissementRemote;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Properties;
     
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.swing.DefaultListModel;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
     
     
    public class Amortissement extends JApplet {
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
    	public Amortissement() {
    	}
    	private JTextField textField;
    	private JTextField textField_4;
    	private JTextField Date;
    	private JTextField annee;
    	private JTextField Duree;
    	private JTable table;
     
     
    	// Initialisation de l'applet
     
    	public void init(){
    	    try {
    	      jbinit();
    	    }
    	    catch(Exception e) {
    	      e.printStackTrace();
    	    }
    	  }
    	/**
             * Create the applet.
             */
    	public void jbinit() throws Exception{
    		getContentPane().setLayout(null);
    		JLabel lblNewLabel = new JLabel("Votre Tableau d'amortissement");
    		lblNewLabel.setFont(new Font("Arial Black", Font.BOLD, 14));
    		lblNewLabel.setBounds(0, 0, 306, 14);
    		getContentPane().add(lblNewLabel);
     
    		JLabel lblretrouverLeDtail = new JLabel("<html>Retrouver <bold> le d\u00E9tail de vos remboursements sur toutes la dur\u00E9e de vos pr\u00EAs immobilier .</bold>Un \u00E9cch\u00E9ancier annuel et mensuel qui met en \u00E9vidence l'\u00E9volutiondu montantdes int\u00E9r\u00EAts de votre pr\u00EAt immobilier et la part de capital amorti.</html>");
    		lblretrouverLeDtail.setBounds(0, 25, 471, 59);
    		getContentPane().add(lblretrouverLeDtail);
     
    		JLabel lblsommeEmprunt = new JLabel("*Somme emprunt\u00E9");
    		lblsommeEmprunt.setFont(new Font("Tahoma", Font.BOLD, 11));
    		lblsommeEmprunt.setBounds(88, 88, 120, 14);
    		getContentPane().add(lblsommeEmprunt);
     
    		JLabel lblDateDeDbut = new JLabel("Date de d\u00E9but de remboursement");
    		lblDateDeDbut.setFont(new Font("Tahoma", Font.BOLD, 11));
    		lblDateDeDbut.setBounds(20, 110, 198, 14);
    		getContentPane().add(lblDateDeDbut);
     
    		JLabel lblDureDuPrt = new JLabel("Dur\u00E9e du pr\u00EAt");
    		lblDureDuPrt.setFont(new Font("Tahoma", Font.BOLD, 11));
    		lblDureDuPrt.setBounds(140, 157, 78, 14);
    		getContentPane().add(lblDureDuPrt);
     
    		JLabel lblTauxAnnuel = new JLabel("Taux annuel");
    		lblTauxAnnuel.setFont(new Font("Tahoma", Font.BOLD, 11));
    		lblTauxAnnuel.setBounds(140, 182, 78, 14);
    		getContentPane().add(lblTauxAnnuel);
     
    		final JTextField Somme = new JTextField();
    		Somme.setBounds(228, 88, 140, 14);
    		getContentPane().add(Somme);
    		Somme.setColumns(10);
     
    		final JTextField Taux = new JTextField();
    		Taux.setColumns(10);
    		Taux.setBounds(228, 182, 140, 14);
    		getContentPane().add(Taux);
     
    		JButton btnNewButton = new JButton("Envoyer");
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    			if(Somme.getText().length() != 0 && Date.getText().length() != 0 && annee.getText().length() != 0 && Duree.getText().length() != 0 && Taux.getText().length() != 0){
    				String somme =  Somme.getText() ;
    				int s = Integer.parseInt(somme);
    				String date =  Date.getText() ;
    				int datee = Integer.parseInt(date);
    				String Annee =  annee.getText() ;
    				int a = Integer.parseInt(Annee);
    				String duree =  Duree.getText() ;
    				int d = Integer.parseInt(duree);
    				String taux =  Taux.getText() ;
    				int t = Integer.parseInt(taux);
     
     
    				envoie_donnee(s,datee,a,d,t);
    			}
    			}
    		});
    		btnNewButton.setBackground(new Color(255, 165, 0));
    		btnNewButton.setForeground(Color.WHITE);
    		btnNewButton.setBounds(238, 207, 89, 23);
    		getContentPane().add(btnNewButton);
     
    		JLabel lblNewLabel_1 = new JLabel("\u20AC");
    		lblNewLabel_1.setBounds(374, 88, 46, 14);
    		getContentPane().add(lblNewLabel_1);
     
     
    		JLabel lblAns = new JLabel("ans");
    		lblAns.setBounds(374, 157, 46, 14);
    		getContentPane().add(lblAns);
     
    		JLabel label = new JLabel("%");
    		label.setBounds(374, 182, 46, 14);
    		getContentPane().add(label);
     
    		Date = new JTextField();
    		Date.setBounds(228, 107, 140, 14);
    		getContentPane().add(Date);
    		Date.setColumns(10);
     
    		annee = new JTextField();
    		annee.setColumns(10);
    		annee.setBounds(228, 132, 140, 14);
    		getContentPane().add(annee);
     
    		Duree = new JTextField();
    		Duree.setColumns(10);
    		Duree.setBounds(228, 157, 140, 14);
    		getContentPane().add(Duree);
     
    		JButton btnRelancer = new JButton("relancer");
    		btnRelancer.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
     
    			}
    		});
    		btnRelancer.setForeground(Color.WHITE);
    		btnRelancer.setBackground(new Color(255, 165, 0));
    		btnRelancer.setBounds(129, 207, 89, 23);
    		getContentPane().add(btnRelancer);
     
    		JButton btnConserver = new JButton("conserver");
    		btnConserver.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				if(Somme.getText().length() != 0 && Date.getText().length() != 0 && annee.getText().length() != 0 && Duree.getText().length() != 0 && Taux.getText().length() != 0){
    					String somme =  Somme.getText() ;
    					int s = Integer.parseInt(somme);
    					String date =  Date.getText() ;
    					int datee = Integer.parseInt(date);
    					String Annee =  annee.getText() ;
    					int a = Integer.parseInt(Annee);
    					String duree =  Duree.getText() ;
    					int d = Integer.parseInt(duree);
    					String taux =  Taux.getText() ;
    					int t = Integer.parseInt(taux);
     
     
    					conserver(s,datee,a,d,t);
    				}
    			}
    		});
    		btnConserver.setForeground(Color.WHITE);
    		btnConserver.setBackground(new Color(255, 165, 0));
    		btnConserver.setBounds(337, 207, 89, 23);
    		getContentPane().add(btnConserver);
     
     
     
     
     
     
     
    	}
     
     
    	   // Connexion au serveur et lookup du bean
        private static AmortissementRemote lookupRemoteStatelessAmortissement() throws NamingException {
      	AmortissementRemote remote=null;
          try {
              Properties jndiProps = new Properties();
              jndiProps.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
              InitialContext ctx = new InitialContext(jndiProps); 
              remote = (AmortissementRemote) ctx.lookup("ejb:/AmortissementEJB/Amortissement!hw.AmortissementRemote");
          	} catch (Exception e) {
              e.printStackTrace();
          		}    	
          return remote;
      }
     
        // Connexion au serveur et lookup du bean
        private static AmortissementAvecEtatRemote lookupRemoteStatelessAvecEtatAmortissement() throws NamingException {
        	AmortissementAvecEtatRemote remote=null;
          try {
              Properties jndiProps = new Properties();
              jndiProps.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
              InitialContext ctx = new InitialContext(jndiProps); 
              remote = (AmortissementAvecEtatRemote) ctx.lookup("ejb:/AmortissementEJB/AmortissementAvecEtat!hw.AmortissementAvecEtatRemote");
          	} catch (Exception e) {
              e.printStackTrace();
          		}    	
          return  remote;
      }
     
     
        public void conserver(int Somme,int Date,int annee,int duree,int taux) {
    		// TODO Auto-generated method stub
    		// Appel du stateless bean
            AmortissementAvecEtatRemote Amortissement;
    		try {
    			Amortissement = lookupRemoteStatelessAvecEtatAmortissement();
    		    Amortissement.calculerAmortissement( Somme, Date, annee, duree, taux);
    		    Object[][] donnee = Amortissement.calculerAmortissement(Somme, Date, annee, duree, taux);
    	         String[] entetes = {"mois", "annee", "mensualite", "amortissement", "interet"};
    	        JTable table = new JTable( donnee,entetes);
    	        table.size();
    	 		table.setBounds(116, 240, 300,300);
    	        getContentPane().add(table);
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    	}
     
        public void afficher_amortissement() {
     		// TODO Auto-generated method stub
     		// Appel du stateless bean
             AmortissementAvecEtatRemote Amortissement;
     		try {
     			Amortissement = lookupRemoteStatelessAvecEtatAmortissement();
     			ArrayList<Object[][]> amortissement = Amortissement.getBuffer();
     	         String[] entetes = {"mois", "annee", "mensualite", "amortissement", "interet"};
     
     
     
     			for(Object[][] tableau : amortissement ) {
     
     
     		        JTable table = new JTable( tableau,entetes);
     
     		 		table.setBounds(116, 240, 300,300);
     		        getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH);
     
     
     
     
     		}
     		}
     
     		 catch (NamingException e) {
     			// TODO Auto-generated catch block
     			e.printStackTrace();
     		}
     
     	}
     
    	public void envoie_donnee(int Somme,int Date,int annee,int duree,int taux) {
    		// TODO Auto-generated method stub
    		// Appel du stateless bean
            AmortissementRemote Amortissement;
    		try {
    			Amortissement = lookupRemoteStatelessAmortissement();
             Object[][] donnee = Amortissement.calculerAmortissement(Somme, Date, annee, duree, taux);
             String[] entetes = {"mois", "annee", "mensualite", "amortissement", "interet"};
            JTable table = new JTable( donnee,entetes);
            table.size();
     	//	table.setBounds(116, 240, 300,300);
            getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH);
     
     
     
     
     
     
     
     
     
     
     
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    	}
    }

    J'utilise windowsbuilder non je ne crois pas avoir mi de layout je savais pas que c'était nécessaire .

  13. #13
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    		getContentPane().setLayout(null);
    Ben tu retire ça, parce que, sans layout, ça ne va pas marcher. Je ne sais pas où tu as été chercher que le layout n'était "pas nécessaire"

    La pluspart des composant swing se comportent mal sans layoutmanager.

  14. #14
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Merci pour votre réponse ,j'ai fais sa mais voilà ce que sa me donne sans cliquer sur rien juste en démarrant mon applet :

    Nom : orange.PNG
Affichages : 401
Taille : 1,9 Ko

    le bouton conserver bouge tout seul parfois le panel s'affiche en orange mais disparaît quand j' agrandit la fenêtre.

  15. #15
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 075
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 075
    Points : 7 980
    Points
    7 980
    Par défaut
    Il faut peut être enlever tout les setBounds(); aussi. Et mettre un layout (un flowLayout ou BoxLayout tout simple par exemple).

    https://docs.oracle.com/javase/tutor...ut/visual.html

    Ensuite quand tu arriveras a revoir tes composants (si tu y arrives), ben tu rejoues avec windowsbuilder (en sauvant ta classe quelques part au cas ou), et tu change le layout et SURTOUT tu lis les tutoriaux
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  16. #16
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Merci j'ai modifié voici le code :

    Code JAVA : 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
    	// Initialisation de l'applet
     
    	public void init(){
    	    try {
    	      jbinit();
    	    }
    	    catch(Exception e) {
    	      e.printStackTrace();
    	    }
    	  }
    	/**
             * Create the applet.
             */
    	public void jbinit() throws Exception{
    		//getContentPane().setLayout(null);
    		setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    		JLabel lblNewLabel = new JLabel("Votre Tableau d'amortissement");
    		lblNewLabel.setFont(new Font("Arial Black", Font.BOLD, 14));
    	//	lblNewLabel.setBounds(0, 0, 306, 14);
    		getContentPane().add(lblNewLabel);
     
     
     
    		JLabel lblsommeEmprunt = new JLabel("*Somme emprunt\u00E9");
    		lblsommeEmprunt.setFont(new Font("Tahoma", Font.BOLD, 11));
    	//	lblsommeEmprunt.setBounds(88, 88, 120, 14);
    		getContentPane().add(lblsommeEmprunt);
    		final JTextField Somme = new JTextField();
    		//	Somme.setBounds(228, 88, 140, 14);
    			getContentPane().add(Somme);
    			Somme.setColumns(10);
     
    		JLabel lblDateDeDbut = new JLabel("moi de d\u00E9but de remboursement");
    		lblDateDeDbut.setFont(new Font("Tahoma", Font.BOLD, 11));
    	//	lblDateDeDbut.setBounds(20, 110, 198, 14);
    		getContentPane().add(lblDateDeDbut);
     
    		Date = new JTextField();
    //		Date.setBounds(228, 107, 140, 14);
    		getContentPane().add(Date);
    		Date.setColumns(10);
     
    		annee = new JTextField();
    		annee.setColumns(10);
    	//	annee.setBounds(228, 132, 140, 14);
    		getContentPane().add(annee);
     
    		JLabel lblDureDuPrt = new JLabel("Dur\u00E9e du pr\u00EAt");
    		lblDureDuPrt.setFont(new Font("Tahoma", Font.BOLD, 11));
    	//	lblDureDuPrt.setBounds(140, 157, 78, 14);
    		getContentPane().add(lblDureDuPrt);
     
    		Duree = new JTextField();
    		Duree.setColumns(10);
    //		Duree.setBounds(228, 157, 140, 14);
    		getContentPane().add(Duree);
     
    		JLabel lblTauxAnnuel = new JLabel("Taux annuel");
    		lblTauxAnnuel.setFont(new Font("Tahoma", Font.BOLD, 11));
    	//	lblTauxAnnuel.setBounds(140, 182, 78, 14);
    		getContentPane().add(lblTauxAnnuel);
     
     
     
    		final JTextField Taux = new JTextField();
    		Taux.setColumns(10);
    	//	Taux.setBounds(228, 182, 140, 14);
    		getContentPane().add(Taux);
     
    		JButton btnNewButton = new JButton("Envoyer");
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    			if(Somme.getText().length() != 0 && Date.getText().length() != 0 && annee.getText().length() != 0 && Duree.getText().length() != 0 && Taux.getText().length() != 0){
    				String somme =  Somme.getText() ;
    				int s = Integer.parseInt(somme);
    				String date =  Date.getText() ;
    				int datee = Integer.parseInt(date);
    				String Annee =  annee.getText() ;
    				int a = Integer.parseInt(Annee);
    				String duree =  Duree.getText() ;
    				int d = Integer.parseInt(duree);
    				String taux =  Taux.getText() ;
    				int t = Integer.parseInt(taux);
     
     
    				envoie_donnee(s,datee,a,d,t);
    			}
    			}
    		});
    		btnNewButton.setBackground(new Color(255, 165, 0));
    		btnNewButton.setForeground(Color.WHITE);
    	//	btnNewButton.setBounds(238, 207, 89, 23);
    		getContentPane().add(btnNewButton);
     
     
     
    		JButton btnRelancer = new JButton("relancer");
    		btnRelancer.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
     
    			}
    		});
    		btnRelancer.setForeground(Color.WHITE);
    		btnRelancer.setBackground(new Color(255, 165, 0));
    //		btnRelancer.setBounds(129, 207, 89, 23);
    		getContentPane().add(btnRelancer);
     
    		JButton btnConserver = new JButton("conserver");
    		btnConserver.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				if(Somme.getText().length() != 0 && Date.getText().length() != 0 && annee.getText().length() != 0 && Duree.getText().length() != 0 && Taux.getText().length() != 0){
    					String somme =  Somme.getText() ;
    					int s = Integer.parseInt(somme);
    					String date =  Date.getText() ;
    					int datee = Integer.parseInt(date);
    					String Annee =  annee.getText() ;
    					int a = Integer.parseInt(Annee);
    					String duree =  Duree.getText() ;
    					int d = Integer.parseInt(duree);
    					String taux =  Taux.getText() ;
    					int t = Integer.parseInt(taux);
     
     
    					conserver(s,datee,a,d,t);
    				}
    			}
    		});
    		btnConserver.setForeground(Color.WHITE);
    		btnConserver.setBackground(new Color(255, 165, 0));
    //		btnConserver.setBounds(337, 207, 89, 23);
    		getContentPane().add(btnConserver, BorderLayout.SOUTH);
     
     
     
     
     
     
     
    	}

    voici ce que j'obtiens :

    Nom : amortiss.PNG
Affichages : 404
Taille : 6,1 Ko

    moi je veux que les jtextfield soit à côté des jlabel et les boutons soit alignés comme dans l'ancien formulaire mais j'ai un peux de mal .

  17. #17
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Ok, on progresse

    Maintenant, tu dois apprendre à découper ton interface en utilisant les layouts. Le layout défini comment un ensemble N de composants de place dans un Conteneur donné. Tu a choisi le box layout vertical, donc tout l'un au dessus de l'autre. Il existe de nombreux autres layouts que je t'invite à consulter. Ensuite, en regroupant dans des panels différent les composants, on peut réaliser les layouts plus complexes que tu cherche à réaliser.

    Dans ton cas, je vois deux alternatives:

    1) le SpringLayout. Je t'invite à consulter sa documentation. Il permet de faire beaucoup de choses, mais sa manipulation est compliquée, peut être trop pour un débutant.

    2) Décomposer. Ton interface superpose différents éléments: Zone de titre, description, formulaire, ensemble de trois boutons, table. Tu peux donc mettre cela dans ton boxlayout vertical actuel, a savoir: un JLabel, un JTextaArea, un JPanel (formulaire), un JPanel (boutons) et le JTable.
    Pour la partie formulaire, tu peux dans le JPanel du formulaire utiliser un GridbagLayout, qui permet d'avoir une grille bien alignée, mais avec les colonnes / lignes de tailles variables (contrairement au GridLayout)
    Pour les trois boutons, tu peux utiliser un panneau avec un FlowLayout ou un BoxLayout horizontal.

  18. #18
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    Je dois donc utiliser plusieurs Jpanel c'est sa que je ne comprend pas trop?

  19. #19
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    un exemple simple ici

    https://docs.oracle.com/javase/tutor...ayout/box.html

    avec un BoxLayout vertical + un Boxlayout horizontal.

  20. #20
    Membre chevronné

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 576
    Points : 1 989
    Points
    1 989
    Par défaut
    très bien merci à tous pour vos réponses je m'est en résolu

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

Discussions similaires

  1. Afficher un tableau de cellule dans une figure
    Par nomad974 dans le forum MATLAB
    Réponses: 2
    Dernier message: 09/06/2015, 20h11
  2. Afficher un tableau à plusieurs dimensions dans une table HTML
    Par doof dans le forum Contribuez / Téléchargez Sources et Outils
    Réponses: 0
    Dernier message: 15/02/2011, 19h38
  3. Afficher le résultat d'une fonction dans une JList
    Par daviddu54 dans le forum Composants
    Réponses: 10
    Dernier message: 01/10/2008, 14h53
  4. Afficher une Hashtable dans une Jlist
    Par pouillou dans le forum Composants
    Réponses: 3
    Dernier message: 26/05/2006, 13h53
  5. afficher un tableau 2 dimensions dans une fenetre
    Par igor24 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 29/04/2006, 13h50

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