GridBagLayout : problème de positionnement
Bonjour
Désolé me revoila avec mes problèmes d'interfaces, je passe plus de temps sur les interfaces que sur le code... :(
J'aimerai faire ceci:
http://www.noelshack.com/uploads/apres031746.png
Une simple fenêtre avec une zone blanche contenant un label et un champ texte. Donc pour ça j'utilise un FlowLayout dans lequel j'ai un JPanel avec pour layout un GridBagLayout. J'ai donné une taille préférée à mon JPanel de 200 * 200.
Or j'arrive qu'à faire ça:
http://www.noelshack.com/uploads/avant009868.png
Je n'arrive pas à faire en sorte que mon champ texte soit juste en dessous de mon label.
Est ce que c'est possible au moins avec un GridBagLayout?
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11
| private JPanel getPanelGeneral() {
if (panelGeneral == null) {
panelGeneral = new JPanel();
FlowLayout flow1 = new FlowLayout();
panelGeneral.setLayout(flow1);
panelGeneral.add(getPanelResultat(), BorderLayout.NORTH);
}
return panelGeneral;
} |
Code:
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
| protected JPanel getPanelResultat() {
if (panelResultat == null) {
panelResultat = new JPanel();
panelResultat.setName("panelResultat");
panelResultat.setLayout(new GridBagLayout());
panelResultat.setBackground(Color.WHITE);
panelResultat.setPreferredSize(new Dimension(200,200));
// Place le label du champ texte
GridBagConstraints gridBagLabel2 = new GridBagConstraints();
gridBagLabel2.gridx = 0;
gridBagLabel2.gridy = 0;
gridBagLabel2.insets = new Insets(5, 5, 5, 5);
gridBagLabel2.gridwidth = 1;
gridBagLabel2.gridheight = 1;
gridBagLabel2.weightx = 1;
gridBagLabel2.weighty = 1;
gridBagLabel2.anchor = GridBagConstraints.NORTHWEST;
panelResultat.add(getLblResultat(),gridBagLabel2);
GridBagConstraints gridBagChampTexte2 = new GridBagConstraints();
gridBagChampTexte2.gridx = 0;
gridBagChampTexte2.gridy = 1;
gridBagChampTexte2.insets = new Insets(5, 5, 5, 5);
gridBagChampTexte2.gridwidth = 1;
gridBagChampTexte2.gridheight = 1;
gridBagChampTexte2.weightx = 1;
gridBagChampTexte2.weighty = 1;
gridBagChampTexte2.anchor = GridBagConstraints.NORTHWEST;
panelResultat.add(getTxtResultat(),gridBagChampTexte2);
}
return panelResultat;
} |
Merci d'avance pour votre aide, je sais plus quoi faire la.