Problème de superposition d'élément graphique
Bonjour,
J'ai un problème d'affichage dans mon application. Je m'explique, je souhaiterai ajouter des JButtons dans un JPanel dont le layoutManager est un GridBagLayout. Le problème est que tous mes JButton se superpose. Je vous donne le code qui ajoute mes éléments au JPanel
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
| public void addPosteToDisplay ()
{
for(int i=0 ; i<this.y ; i++)
{
for(int j=0 ; j<this.x ; j++)
{
try
{
this.c.weightx = 0.5;
this.c.fill = GridBagConstraints.BOTH;
this.c.gridx = j;
this.c.gridy = i;
this.c.gridwidth = 1;
this.c.gridheight = 1;
System.out.println("x:"+this.y+" y:"+this.x+" || "+this.tabPoste[i][j].getLabel());
this.add(this.tabPoste[i][j],this.c);
}
catch (Exception e)
{
this.c.weightx = 0.5;
this.c.fill = GridBagConstraints.BOTH;
this.c.gridx = j;
this.c.gridy = i;
this.c.gridwidth = 1;
this.c.gridheight = 1;
this.add(new JButton(),this.c);
}
}
}
} |
J'ai agrandit suffisamment mes JPanel pour qu'il y ait de la place. Autre chose même en utilisant un layoutManager différent les JButton se superpose.
Quelqu'un a-t-il la solution à mon problème s'il vous plait.
Merci d'avance pour vos réponses