pas voir boutons (AWT / GridBagLayout)
mon problème c'est qu'avec le début de bout de code suivant, je n'ai que la Frame qui s'affiche, pas les petits boutons que je m'attendais à voir former une sorte de diagonale. :(
Can you tell me why ?
NB: les classes main et myWindow sont dans deux fichiers différents :zoubi: Toute la partie événementielle n'est pas là :bebe:
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 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
| import java.awt.Frame;
import java.awt.Button;
import java.awt.GridBagConstraints;
import java.awt.LayoutManager;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Dimension;
public class main {
public static void main(String[] args) {
myWindow appWin = new myWindow();
}
}
public class myWindow extends Frame {
LayoutManager oLayoutManager;
GridBagConstraints oConstraints;
Button Button1;
Button Button2;
Button Button3;
Frame mainCentralFrame;
public myWindow() {
layoutManagerInit();
componentsAdd();
listenersInit();
windowSizeAndPlaceInit();
componentsLayout();
this.setVisible(true);
}
void layoutManagerInit()
{
oLayoutManager = new GridBagLayout();
oConstraints = new GridBagConstraints();
oLayoutManager.layoutContainer(this);
}
void componentsAdd()
{
Button1 = new Button();
Button2 = new Button();
Button3 = new Button();
Button1.setVisible(true);
Button2.setVisible(true);
Button3.setVisible(true);
}
void windowSizeAndPlaceInit()
{
Point p = new Point(200, 100);
Dimension d = new Dimension(800, 600);
Rectangle defaultBoundRect = new Rectangle(p, d);
this.setBounds(defaultBoundRect);
}
void componentsLayout()
{
oConstraints.gridx = 0;
oConstraints.gridy = 0;
oConstraints.gridheight = 1;
oConstraints.gridwidth = 1;
oLayoutManager.addLayoutComponent("machin", Button1);
oConstraints.gridx = 1;
oConstraints.gridy = 1;
oLayoutManager.addLayoutComponent("bidule", Button2);
oConstraints.gridx = 2;
oConstraints.gridy = 2;
oLayoutManager.addLayoutComponent("truc", Button3);
}
void listenersInit()
{
}
} |
merci, je comprends mieux
j'avais pas compris que la relation entre le layoutManager et le container était basée sur des sortes d'états à des moments précis, comme des snapshots...
ok :merci: