Bonjour tout le monde .
J'ai mon applet qui se centre verticalement au milieu de la page.
Moi je veux qu'il se mette en haut et qu'il y reste.
HELP SVP.
Merci
code :
//******* affichage du tableau ********
// pour que le composant utilise toute la place
c.fill = GridBagConstraints.BOTH;
// première zone : le titre du tableau
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = 1;
c.weightx = 4;
titretab = new Label(titre, Label.CENTER);
if (titre.length() < 50) {
titretab.setFont(new Font("Helvetica", Font.PLAIN, 22));}
else {titretab.setFont(new Font("Helvetica", Font.PLAIN, 10));}
titretab.setBackground(Color.white);
gridbag.setConstraints(titretab, c);
add(titretab);
// 2e zone: le tableau, avec un panel où le mettre
Panel tableau = new Panel();
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = 1;
c.weightx = 20;
GridBagLayout grille = new GridBagLayout();
GridBagConstraints cg = new GridBagConstraints();
cg.insets = new Insets(1,1,1,1); // écart entre les labels du tableau
gridbag.setConstraints(tableau, c);
tableau.setBackground(Color.white);
tableau.setLayout(grille);
Color coule = new Color(219,226,249); // couleur du fond du tableau
// composants du tableau
setFont(new Font("Arial", Font.PLAIN, 12));
cg.fill = GridBagConstraints.BOTH;
cg.weighty = 1;
// 1ère ligne - co +1 colonnes, première colonne taille 2
// on n'affiche que 8 caractères par titre de colonne
Label titres[] = new Label[co+1];
for (int i = 0; i<co+1; i ++) {
String ss;
ss = col[i];
if (i >0 & ss.length() > 7) {ss = ss.substring(0,8);}
titres[i] = new Label(ss, Label.CENTER);
titres[i].setBackground(coule);
if (i == 0 ) {
cg.weightx = 2;
}
else {
cg.weightx = 1;
}
if (i == co) {
cg.gridwidth = GridBagConstraints.REMAINDER; //end row
}
grille.setConstraints(titres[i],cg);
tableau.add(titres[i]);
}
// autres lignes
cg.gridwidth = 1;
Label ele[][] = new Label[l+1][co+1];
// transformation du tableau en lettres pour affichage dans le label
String tablettres[][] = new String[l][co];
for (int j = 0; j<l; j ++){
for (int i =0; i<co; i ++){
tablettres[j][i] = Double.toString(tab[j][i]);
}
}
// affichage
for (int j = 0; j<l; j ++){
cg.weightx = 2;
cg.gridwidth = 1;
ele[j][0] = new Label(lig[j], Label.LEFT);
ele[j][0].setBackground(coule);
grille.setConstraints(ele[j][0],cg);
tableau.add(ele[j][0]);
for (int i = 0; i<co; i ++) {
cg.weightx = 1;
ele[j][i+1] = new Label(tablettres[j][i], Label.CENTER);
ele[j][i+1].setBackground(coule);
if (i == co-1) {
cg.gridwidth = GridBagConstraints.REMAINDER; //end row
}
grille.setConstraints(ele[j][i+1],cg);
tableau.add(ele[j][i+1]);
}
}
add(tableau);
// 4e zone : les consignes
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = 1;
setFont(new Font("Arial", Font.PLAIN, 12));
consignes2 = new Label("Cliquez sur un des boutons pour faire un graphique. ", Label.CENTER);
gridbag.setConstraints(consignes2, c);
consignes2.setBackground(Color.yellow);
add(consignes2);
// 3 boutons pour faire un graphique
b5 = new Button(" courbes ");
b6 = new Button(" bâtons ");
b7 = new Button(" nuage de points ");
add(b5);
b5.addActionListener(this);
add(b6);
b6.addActionListener(this);
add(b7);
b7.addActionListener(this);
// taille de la fenêtre (à donner dans la page html)
setSize(400 + 20 * co, 220 + 10 * l);