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

Agents de placement/Fenêtres Java Discussion :

[débutant]GridBagLayout


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut [débutant]GridBagLayout
    Bonjour,

    j'aimerai créer un Panel composé comme ça:



    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
     
     
    ___________________________________________________________
     
           _identifiant______________
           |                         |
           |   bague  stam  année    |   
           |   _____  ____  _____    |
           |   |____| |___| |____|   |    
           |_________________________|
     
                  ______
            Sexe:|_____|
                  ______
            Pere:|_____|
                  ______
            Mere:|_____|
    avec
    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
     
    public class AjoutCanariPanel extends JPanel{
     
    	/* --- Attributs --- */ 
     
    	private Vector nbBague = new Vector();
    	private final String[] genre = { "Mâle", "Femelle","Non défini" };
    	private static final int   NB_BAGUE_MAX  = 999;
     
    	private JTextField stamField = new JTextField(10);
    	private JTextField anneeField = new JTextField(10);
    	private JTextField pereField = new JTextField(10);
    	private JTextField mereField = new JTextField(10);
     
    	private JComboBox bagueCombo;
    	private JComboBox sexeCombo= new JComboBox(genre);
     
    	private JLabel identifiantLabel = new JLabel("Identifiant :");
    	private JLabel anneeLabel = new JLabel("Année");
    	private JLabel stamLabel = new JLabel("Stam");
    	private JLabel bagueLabel = new JLabel("Bague");
    	private JLabel sexeLabel = new JLabel("Sexe :");
    	private JLabel pereLabel = new JLabel("Père :");
    	private JLabel mereLabel = new JLabel("Mère :");
     
    	private JPanel panelIdentifiant;
     
     
    	public AjoutCanariPanel(){
    		super();		
    		init();
    	}
     
    	public void init(){		
    		GridBagLayout gridbag = new GridBagLayout(); 	   
    		GridBagConstraints c = new GridBagConstraints(); 
    		setLayout(gridbag); 
    	    c.fill = GridBagConstraints.CENTER;
    	    identifiantPanel();
    	    /*gridbag.setConstraints(identifiantLabel,c); 
    	    add(identifiantLabel);
    	    c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)*/
    	    gridbag.setConstraints(panelIdentifiant,c); 
    	    add(panelIdentifiant);
    	    c.gridwidth = GridBagConstraints.RELATIVE;
    	    gridbag.setConstraints(sexeLabel,c); 
    	    add(sexeLabel);
    	    c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    gridbag.setConstraints(sexeCombo,c); 
    	    add(sexeCombo);
    	    c.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
    	    gridbag.setConstraints(pereLabel,c);
    	    add(pereLabel);
    	    c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    gridbag.setConstraints(pereField,c);
    	    add(pereField);
    	    c.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
    	    gridbag.setConstraints(mereLabel,c);
    	    add(mereLabel);
    	    c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    gridbag.setConstraints(mereField,c);
    	    add(mereField);
     
    	}
     
    	public void identifiantPanel(){
    		for (int i = 1; i <= NB_BAGUE_MAX; i++) 
            {       	
             nbBague.addElement(""+i);	       	     	       	       
            }
    		bagueCombo = new JComboBox(nbBague);
    		panelIdentifiant = new JPanel();				
    		GridBagLayout grid = new GridBagLayout(); 	   
    		GridBagConstraints co = new GridBagConstraints();
    		co.fill = GridBagConstraints.BOTH;
    		grid.setConstraints(bagueLabel,co); 
    		panelIdentifiant.add(bagueLabel);
    	    co.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    grid.setConstraints(stamLabel,co); 
    	    panelIdentifiant.add(stamLabel);
    	    co.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    grid.setConstraints(anneeLabel,co); 
    	    panelIdentifiant.add(anneeLabel);
    	    co.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
    	    grid.setConstraints(bagueCombo,co); 
    	    panelIdentifiant.add(bagueCombo);
    	    co.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    grid.setConstraints(stamField,co); 
    	    panelIdentifiant.add(stamField);
    	    co.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
    	    grid.setConstraints(anneeField,co); 
    	    panelIdentifiant.add(anneeField);
    	    panelIdentifiant.setBorder(BorderFactory.createTitledBorder("Identifiant:"));
    	}
     
    }
    En faisaint ainsi, j'ai un problème de disposition du panelidentifiant

    pourvez vous m'orienter pour faire un panel sympa
    merci

  2. #2
    Membre éprouvé
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Points : 935
    Points
    935
    Par défaut
    cele t'irais cela ?
    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
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.util.Vector;
    import javax.swing.*;
     
    public class AjoutCanariPanel extends JPanel{
     
       /* --- Attributs --- */
     
       private Vector nbBague = new Vector();
       private final String[] genre = { "Mâle", "Femelle","Non défini" };
       private static final int   NB_BAGUE_MAX  = 999;
     
       private JTextField stamField = new JTextField(10);
       private JTextField anneeField = new JTextField(10);
       private JTextField pereField = new JTextField(10);
       private JTextField mereField = new JTextField(10);
     
       private JComboBox bagueCombo;
       private JComboBox sexeCombo= new JComboBox(genre);
     
       private JLabel identifiantLabel = new JLabel("Identifiant :");
       private JLabel anneeLabel = new JLabel("Année");
       private JLabel stamLabel = new JLabel("Stam");
       private JLabel bagueLabel = new JLabel("Bague");
       private JLabel sexeLabel = new JLabel("Sexe :");
       private JLabel pereLabel = new JLabel("Père :");
       private JLabel mereLabel = new JLabel("Mère :");
     
       private JPanel panelIdentifiant;
     
     
       public AjoutCanariPanel(){
          super();      
          init();
       }
     
       public void init(){      
          GridBagLayout gridbag = new GridBagLayout();       
          GridBagConstraints c = new GridBagConstraints();
          setLayout(gridbag);
           identifiantPanel();
           c.anchor=GridBagConstraints.WEST;
           /*gridbag.setConstraints(identifiantLabel,c);
           add(identifiantLabel);*/
           c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
           gridbag.setConstraints(panelIdentifiant,c);
           add(panelIdentifiant);
           c.gridwidth = GridBagConstraints.RELATIVE;
           gridbag.setConstraints(sexeLabel,c);
           add(sexeLabel);
           c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
           gridbag.setConstraints(sexeCombo,c);
           add(sexeCombo);
           c.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
           gridbag.setConstraints(pereLabel,c);
           add(pereLabel);
           c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
           gridbag.setConstraints(pereField,c);
           add(pereField);
           c.gridwidth = GridBagConstraints.RELATIVE; // en dessous du premier label
           gridbag.setConstraints(mereLabel,c);
           add(mereLabel);
           c.gridwidth = GridBagConstraints.REMAINDER; //A côté du label (end row)
           gridbag.setConstraints(mereField,c);
           add(mereField);
     
       }
     
    	public void identifiantPanel() {
    		for (int i = 1; i <= NB_BAGUE_MAX; i++) {
    			nbBague.addElement("" + i);
    		}
    		bagueCombo = new JComboBox(nbBague);
    		GridBagLayout grid = new GridBagLayout();
    		panelIdentifiant = new JPanel(grid);
     
    		GridBagConstraints co = new GridBagConstraints();
    		co.fill = GridBagConstraints.HORIZONTAL;
     
    		co.gridx = 0;
    		co.gridy = 0;
    		grid.setConstraints(bagueLabel, co);
    		panelIdentifiant.add(bagueLabel);
    		co.gridx = 1;
    		co.gridy = 0;
    		grid.setConstraints(stamLabel, co);
    		panelIdentifiant.add(stamLabel);
    		co.gridx = 2;
    		co.gridy = 0;
    		grid.setConstraints(anneeLabel, co);
    		panelIdentifiant.add(anneeLabel);
     
     
    		co.gridx = 0;
    		co.gridy = 1;
    		grid.setConstraints(bagueCombo, co);
    		panelIdentifiant.add(bagueCombo);
    		co.gridx = 1;
    		co.gridy = 1;
    		grid.setConstraints(stamField, co);
    		panelIdentifiant.add(stamField);
    		co.gridx = 2;
    		co.gridy = 1;
    		grid.setConstraints(anneeField, co);
    		panelIdentifiant.add(anneeField);
    		panelIdentifiant.setBorder(
    		BorderFactory.createTitledBorder("Identifiant:"));
    	}
     
    }

  3. #3
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    Parfait !
    je ferai le reste de la dispositions suivant ce model


  4. #4
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    un autre petite question:
    où dois placé un listener pour récupérer les champs remplis?

    dansAjoutCanariPanel qui est le panel avec les textField, combobox, etc

    dans AjouterCanari qui est la JDialog qui contient le JPanel AjoutCanariPanel

  5. #5
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    C'est bon! C'est résolu !

    Une réponse à un autre sujet m'a permis de comprendre comment mettre en ouvre mon listener


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

Discussions similaires

  1. [débutant] problème GridBagLayout
    Par cyrill.gremaud dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 08/11/2006, 09h23
  2. [débutant] alignement vertical + GridBagLayout
    Par cyrill.gremaud dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 02/11/2006, 13h04
  3. Réponses: 2
    Dernier message: 22/05/2006, 11h34
  4. Réponses: 3
    Dernier message: 07/05/2002, 16h06
  5. [HyperFile] 2 questions de débutant
    Par khan dans le forum HyperFileSQL
    Réponses: 2
    Dernier message: 29/04/2002, 23h18

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