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 :

Problème affichage GridLayout()


Sujet :

Composants Java

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Avril 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : Belgique

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Avril 2014
    Messages : 7
    Points : 5
    Points
    5
    Par défaut Problème affichage GridLayout()
    Bonjour,

    J'ai un soucis avec mon code java, mon panneau JPanel button s'affiche bien dans ma fenêtre mais pas mon JPanel formulaire en GridLayout...
    Je vous poste mon code :


    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
    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
    package v1;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Types;
    import java.util.GregorianCalendar;
     
    import javax.swing.*;
     
    public class FormulaireAjout extends JFrame {
     
    	private FenetrePrincipale fen;
    	private JLabel labIDInstal, labDateInst, labCom, labDuree, labRefProc, labCodeSoft, labRespRes, labCodeOS, labProf;
    	private JTextField jtfIDInstal, jtfDateInst, jtfCom, jtfDuree, jtfRefProc;
    	private JPanel jpForm, jpBut;
    	private JButton butok, butreset, butRet;
    	private JComboBox<String> jcbCodeOS, jcbSoft, jcbRespRes, jcbProf;
    	Object[] tabRespres, tabProf, tabCodeOS, tabCodeSoft;
    	private Container cont;
     
    	public FormulaireAjout(FenetrePrincipale f) {
    		super("Ajout");
    		try {
     
    			this.fen = f;
    			this.setBounds(0, 0, 700, 500);
    			this.setLocationRelativeTo(null);
     
    			jpBut = new JPanel();
    			jpBut.setLayout(new FlowLayout());
    			jpForm = new JPanel();
    			jpForm.setLayout(new GridLayout());
     
    			labIDInstal = new JLabel("ID Instal :");
    			labIDInstal.setHorizontalAlignment(SwingConstants.RIGHT);
     
     
     
    			labDateInst = new JLabel("date instal (AAAAMMJJ) :");
    			labDateInst.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labCom = new JLabel("Commentaire :");
    			labCom.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labDuree = new JLabel("Durée (min) :");
    			labDuree.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labRefProc = new JLabel("Reférence de la procédure :");
    			labRefProc.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labCodeSoft = new JLabel("Code Software :");
    			labCodeSoft.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labRespRes = new JLabel("Responsable réseau :");
    			labRespRes.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labProf = new JLabel("professeur :");
    			labProf.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			labCodeOS = new JLabel("Code OS :");
    			labCodeOS.setHorizontalAlignment(SwingConstants.RIGHT);
     
    			jtfIDInstal = new JTextField(10);
    			ActForm aLForm = new ActForm();
    			jtfIDInstal.addActionListener(aLForm);
    			jtfDateInst = new JTextField(8);
    			jtfCom = new JTextField(50);
    			jtfDuree = new JTextField(4);
    			jtfRefProc = new JTextField(10);
     
     
     
    			butok = new JButton("Ok");
    			butreset = new JButton("Reset");
    			butRet = new JButton("Retour");
     
    			butreset.addActionListener(aLForm);
    			butok.addActionListener(aLForm);
    			butRet.addActionListener(aLForm);
     
     
     
    			jpBut.add(butRet);
    			jpBut.add(butreset);
    			jpBut.add(butok);
     
    		    cont = getContentPane();
    			cont.setLayout(new BorderLayout());
    			cont.add(jpForm, BorderLayout.NORTH);
    			cont.add(jpBut, BorderLayout.SOUTH); 
     
     
    			String sqlInstr;
    			sqlInstr = "select Matricule from responsableReseaux order by Matricule ";
    			PreparedStatement psRespres = fen.getMaConnexion().prepareStatement(sqlInstr);
    			tabRespres = AccessBDGen.creerListe1Colonne(psRespres);
     
    			sqlInstr = "select NomPrenom from responsableReseaux order by NomPrenom ";
    			PreparedStatement psRespResNom = fen.getMaConnexion().prepareStatement(sqlInstr);
    			Object[] tabRespResNom = AccessBDGen.creerListe1Colonne(psRespResNom);
     
    			sqlInstr = "select CodeProf from Professeur order by CodeProf ";
    			PreparedStatement psProf = fen.getMaConnexion().prepareStatement(sqlInstr);
    			tabProf = AccessBDGen.creerListe1Colonne(psProf);
     
    			sqlInstr = "select NomPrenom from Professeur order by NomPrenom";
    			PreparedStatement psProfNom = fen.getMaConnexion().prepareStatement(sqlInstr);
    			Object[] tabProfNom = AccessBDGen.creerListe1Colonne(psProfNom);
     
    			sqlInstr = "select CodeSoftware from Software order by CodeSoftware";
    			PreparedStatement psCodeSoftware = fen.getMaConnexion().prepareStatement(sqlInstr);
    			tabCodeSoft = AccessBDGen.creerListe1Colonne(psCodeSoftware);
     
    			sqlInstr = "select Nom from Software order by CodeSoftware";
    			PreparedStatement psNomCodeSoftware = fen.getMaConnexion().prepareStatement(sqlInstr);
    			Object[] TabNomCodeSoftware = AccessBDGen.creerListe1Colonne(psNomCodeSoftware);
     
    			sqlInstr = "select CodeOS from Os order by CodeOS";
    			PreparedStatement psCodeOS = fen.getMaConnexion().prepareStatement(sqlInstr);
    			tabCodeOS = AccessBDGen.creerListe1Colonne(psCodeOS);
     
    			sqlInstr = "select Libelle from Os order by CodeOS";
    			PreparedStatement psNomCodeOS = fen.getMaConnexion().prepareStatement(sqlInstr);
    			Object[] TabNomCodeOS = AccessBDGen.creerListe1Colonne(psNomCodeOS);
     
    			jcbCodeOS = new JComboBox(tabCodeOS);
    			jcbSoft = new JComboBox(tabCodeSoft);
    			jcbRespRes = new JComboBox(tabRespres);
    			jcbProf = new JComboBox(tabProf);
     
    			jpForm.add(labIDInstal);
    			jpForm.add(jtfIDInstal);
    			jpForm.add(labCodeSoft);
    			jpForm.add(jcbSoft);
    			jpForm.add(labCodeOS);
    			jpForm.add(jcbCodeOS);
    			jpForm.add(labDateInst);
    			jpForm.add(jtfDateInst);
    			jpForm.add(labDuree);
    			jpForm.add(jtfDuree);
    			jpForm.add(labRespRes);
    			jpForm.add(jcbRespRes);
    			jpForm.add(labProf);
    			jpForm.add(jcbProf);
    			jpForm.add(labRefProc);
    			jpForm.add(jtfRefProc);
    			jpForm.add(labCom);
    			jpForm.add(jtfCom);
     
    			this.setVisible(true);
     
    		}
     
    		catch (Exception e) {
     
    			e.printStackTrace();
    		}
    	}
     
    private class ActForm implements ActionListener {
    		public void actionPerformed(ActionEvent e) {
     
    			if (e.getSource() == butreset) {
     
    				jtfIDInstal.setText("");
    				jtfDateInst.setText("");
    				jtfDuree.setText("");
    				jtfRefProc.setText("");
    				jtfCom.setText("");
     
    			}
     
    			if (e.getSource() == butRet) {
    				fen.getCont().removeAll();
    				PanneauAccueil panAcc = new PanneauAccueil(fen);
    				fen.getCont().add(panAcc);
    				fen.getCont().repaint();
    				fen.getCont().setVisible(true);
    			}
     
    			if (e.getSource() == butok) {
     
    				String date = jtfDateInst.getText();
     
    				try {
    					if (date.length() != 8)
    						throw new ExceptionDate(date);
     
    					String an = date.substring(0, 4);
    					String mo = date.substring(4, 6);
    					String jo = date.substring(6, 8);
     
    					int j = Integer.parseInt(jo);
    					int m = Integer.parseInt(mo);
    					int a = Integer.parseInt(an);
     
    					String sqlInstruction = "insert into installation(IdInstallation,DateInstallation,"
    							+ "Commentaires,DureeInstallation,RefProcedureInstallation,"
    							+ "CodeSoftware,Matricule,CodeOs) values (?,?,?,?,?,?,?,?)";
    					PreparedStatement myPrepStat = fen.getMaConnexion().prepareStatement(sqlInstruction);
     
    					if (jtfIDInstal.getText().equals("") == false)
    						myPrepStat.setInt(1, Integer.parseInt(jtfIDInstal.getText()));
    					else {
    						throw new ExceptionChampVide("IdInstallation");
    					}
     
    					myPrepStat.setDate(2, new java.sql.Date(new GregorianCalendar(a, m - 1, j).getTimeInMillis()));
     
    					if (jtfCom.getText().equals("") == false)
    						myPrepStat.setString(3, jtfCom.getText());
    					else
    						myPrepStat.setNull(3, Types.VARCHAR);
     
    					if (jtfDuree.getText().equals("") == false)
    						myPrepStat.setInt(4, Integer.parseInt(jtfDuree.getText()));
    					else
    						myPrepStat.setNull(4, Types.SMALLINT);
     
    					if (jtfRefProc.getText().equals("") == false)
    						myPrepStat.setString(5, jtfRefProc.getText());
    					else
    						myPrepStat.setNull(5, Types.VARCHAR);
     
    					String codeOS = (String) tabCodeOS[jcbCodeOS.getSelectedIndex()];
    					myPrepStat.setString(8, codeOS);
     
    					String codeSoft = (String) tabCodeSoft[jcbSoft.getSelectedIndex()];
    					myPrepStat.setString(8, codeSoft);
     
    					String RespRes = (String) tabRespres[jcbRespRes.getSelectedIndex()];
    					myPrepStat.setString(16, RespRes);
     
    					String Prof = (String) tabProf[jcbProf.getSelectedIndex()];
    					myPrepStat.setString(16, Prof);
     
    				}
     
    				catch (ExceptionChampVide e3) {
    					JOptionPane.showMessageDialog(null, e3, "Le champs est vide", JOptionPane.ERROR_MESSAGE);
    				}
     
    				catch (NumberFormatException e4) {
    					JOptionPane.showMessageDialog(null, e4.getMessage(), "Le numéro est incorrect",
    							JOptionPane.ERROR_MESSAGE);
    				}
     
    				catch (ExceptionDate e1) {
    					JOptionPane.showMessageDialog(null, e1, "La date est incorrecte", JOptionPane.ERROR_MESSAGE);
    				}
     
    				catch (Exception e2) {
    					JOptionPane.showMessageDialog(null, e2.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
    				}
     
    			}
     
    		}
    	}
    }
    Merci d'avance pour votre aide et vos futures réponses

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Il faudrait être un peu plus précis au sujet de l'affichage du "panel" : le panel ne s'affiche pas du tout, ou s'affiche-t-il partiellement, ou pas comme tu l'attends ?

    A noter que la grille du "GridLayout" ne fait qu'une seule ligne : ne t'attends donc pas à voir une grille. Il faut indiquer soit un nombre de ligne, soit un nombre de colonnes, lors de la construction.
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

Discussions similaires

  1. Réponses: 10
    Dernier message: 08/06/2009, 11h30
  2. problème affichage image
    Par thealpacino dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 30/05/2005, 13h56
  3. Problème affichage primitive
    Par goutbouyo dans le forum DirectX
    Réponses: 4
    Dernier message: 29/12/2004, 18h25
  4. [Plugin][VE] Problème affichage
    Par sebb84 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 05/07/2004, 14h50
  5. [DOS] Problème affichage de DOS dans un Memo
    Par Pedro dans le forum API, COM et SDKs
    Réponses: 9
    Dernier message: 25/06/2004, 13h31

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