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 :

GridLayoutBag : problème d'alignement


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé

    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    310
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 310
    Par défaut GridLayoutBag : problème d'alignement
    Bonjour

    Je souhaite faire une fenetre de ce style là à l'aide d'un GridBagLayout.


    Donc un label + un champ texte aligné sur la gauche et un bouton valider plus bas à droite. Rien de bien compliqué normalement sauf que pour une raison inconnue, mon label et mon champ texte sont centrés.



    Quelqu'un saurait pourquoi est ce que mon label et mon champ texte sont centrés? Merci d'avance

    Code utilisé:
    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
    panelFenetre= new JPanel();
    panelFenetre.setLayout(new BorderLayout());
    this.setContentPane(panelFenetre);
     
     
    // Place les composants
    panelFenetre.add(getPanelBouton(), BorderLayout.NORTH);
     
    	private JPanel getPanelBouton() {
    			panelBouton = new JPanel();
    			panelBouton.setName("panelBoutons");
    			panelBouton.setLayout(new GridBagLayout());
    			panelBouton.setBackground(Color.WHITE);
     
    			// Place le label du champ texte
    			GridBagConstraints gridBagLabel1 = new GridBagConstraints();
    			gridBagLabel1.gridx = 0;
    			gridBagLabel1.gridy = 0;
    			gridBagLabel1.insets = new Insets(5, 5, 5, 5);
    			gridBagLabel1.gridwidth = 1;
    			gridBagLabel1.gridheight = 1;
    			gridBagLabel1.weightx = 0;
    			gridBagLabel1.weighty = 0;
    			gridBagLabel1.ipadx = 0;
    			gridBagLabel1.ipady = 0;
    			gridBagLabel1.anchor = GridBagConstraints.NORTHWEST;
    			panelBouton.add(getLblPhrase(), gridBagLabel1);
     
    			GridBagConstraints gridBagChampTexte = new GridBagConstraints();
    			gridBagChampTexte.gridx = 0;
    			gridBagChampTexte.gridy = 1;
    			gridBagChampTexte.insets = new Insets(5, 5, 5, 5);
    			gridBagChampTexte.gridwidth = 1;
    			gridBagChampTexte.gridheight = 1;
    			gridBagChampTexte.weightx = 0;
    			gridBagChampTexte.weighty = 0;
    			gridBagChampTexte.ipadx = 0;
    			gridBagChampTexte.ipady = 0;
    			gridBagChampTexte.anchor = GridBagConstraints.NORTHWEST;
    			panelBouton.add(getTxtPhrase(), gridBagChampTexte);
     
    			// Place le bouton Valider
    			GridBagConstraints gridBagValider = new GridBagConstraints();
    			gridBagValider.gridx = 1;
    			gridBagValider.gridy = 2;
    			gridBagValider.insets = new Insets(5, 5, 5, 5);
    			gridBagValider.gridwidth = 1;
    			gridBagValider.gridheight = 1;
    			gridBagValider.weightx = 0;
    			gridBagValider.weighty = 0;
    			gridBagValider.ipadx = 0;
    			gridBagValider.ipady = 0;
    			gridBagValider.anchor = GridBagConstraints.NORTHWEST;
    			panelBouton.add(getCmdValider(), gridBagValider);
     
    		return panelBouton;
    	}

  2. #2
    Membre Expert
    Avatar de visiwi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    1 052
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 1 052
    Par défaut
    Salut,

    Met tes propriétés weightx à 1.0

  3. #3
    Membre éclairé

    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    310
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 310
    Par défaut
    Merci ça marche! Par contre mon bouton Valider se déplace si j'élargie la fenêtre même avec weightx = 1.0

    Est ce qu'il y a un paramètre particulier pour celui ci? Merci

  4. #4
    Membre Expert
    Avatar de visiwi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    1 052
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 1 052
    Par défaut
    Je pense à :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    gridBagValider.gridwidth = GridBagConstraints.REMAINDER;
    EDIT / ->
    désolé, j'ai dit n'importe quoi, j'avais un peu oublier ta préoccupation précédente .

    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
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class Test {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
     
    		JFrame f = new JFrame();
    		JPanel panelFenetre = new JPanel();
    		panelFenetre.setLayout(new BorderLayout());
    		f.setContentPane(panelFenetre);
    		panelFenetre.add(getPanelBouton());
    		f.setVisible(true);
    	}
     
    	private static JPanel getPanelBouton() {
    		JPanel panelBouton = new JPanel();
    		panelBouton.setName("panelBoutons");
    		panelBouton.setLayout(new GridBagLayout());
    		panelBouton.setBackground(Color.WHITE);
     
    		// Place le label du champ texte
    		GridBagConstraints gridBagLabel1 = new GridBagConstraints();
    		gridBagLabel1.gridx = 0;
    		gridBagLabel1.gridy = 0;
    		gridBagLabel1.insets = new Insets(5, 5, 5, 5);
    		gridBagLabel1.gridwidth = 1;
    		gridBagLabel1.gridheight = 1;
    		gridBagLabel1.weightx = 0;
    		gridBagLabel1.weighty = 0;
    		gridBagLabel1.ipadx = 0;
    		gridBagLabel1.ipady = 0;
    		gridBagLabel1.anchor = GridBagConstraints.NORTHWEST;
    		panelBouton.add(new JLabel("getLblPhrase()"), gridBagLabel1);
     
    		GridBagConstraints gridBagChampTexte = new GridBagConstraints();
    		gridBagChampTexte.gridx = 0;
    		gridBagChampTexte.gridy = 1;
    		gridBagChampTexte.insets = new Insets(5, 5, 5, 5);
    		gridBagChampTexte.gridwidth = 1;
    		gridBagChampTexte.gridheight = 1;
    		gridBagChampTexte.weightx = 0;
    		gridBagChampTexte.weighty = 0;
    		gridBagChampTexte.ipadx = 0;
    		gridBagChampTexte.ipady = 0;
    		gridBagChampTexte.anchor = GridBagConstraints.NORTHWEST;
    		panelBouton.add(new JLabel("getTxtPhrase()"), gridBagChampTexte);
     
    		// Place le bouton Valider
    		GridBagConstraints gridBagValider = new GridBagConstraints();
    		gridBagValider.gridx = 1;
    		gridBagValider.gridy = 2;
    		gridBagValider.insets = new Insets(5, 5, 5, 5);
    		gridBagValider.gridwidth = 1;
    		gridBagValider.gridheight = 1;
    		gridBagValider.weightx = 1.0;
    		gridBagValider.weighty = 1.0;
    		gridBagValider.ipadx = 0;
    		gridBagValider.ipady = 0;
    		gridBagValider.anchor = GridBagConstraints.FIRST_LINE_START;
     
    		panelBouton.add(new JButton("getCmdValider()"), gridBagValider);
     
    		return panelBouton;
    	}
    }

  5. #5
    Membre éclairé

    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    310
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 310
    Par défaut
    Merci ça marche ^^
    Je suis décidément pas doué pour tout ce qui concerne les interfaces graphiques XD Bien joué

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

Discussions similaires

  1. [CSS] Problème d'alignement des images
    Par Walabar dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 04/08/2006, 15h42
  2. débutant, problème d'alignement...
    Par celmakie dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 01/04/2006, 21h13
  3. problème d'alignement swing
    Par demonia dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 19/02/2006, 21h47
  4. Réponses: 1
    Dernier message: 22/12/2005, 11h23
  5. Problème d'alignement
    Par zorely dans le forum Mise en forme
    Réponses: 4
    Dernier message: 09/08/2005, 10h52

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