bonjour je me lance avec des pieds de plombs dans la programmations graphique en java et malheureusement je rencontre pas mal de problèmes.
Avant d'utiliser les programme de mise en forme comme jbuilder ou le module de eclipse je veux coder mon interface moi même.

Mon probleme est le suivant, mon gridLayout n'est pas respecté dans mon JPanel
je précise 7 colonnes et ils m'en donnent au moins 9 ....

Merci d'avance

voici mon code:

Ma classe JFrame
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
 
class MaFenetre extends JFrame implements MouseMotionListener{
	private int locationX,locationY;
	java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
	public MaFenetre(){
		addMouseMotionListener(this);
		this.setTitle("Calendrier");
		this.setSize(200,200);
 
		this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
 
		this.setResizable(false);
 
 
		this.setUndecorated(true);
 
 
		Container container = getContentPane ();
 
		container.add(new Cal());//cal est ma classe JPanel
 
 
		this.setLocation(screenSize.width-this.getWidth()-40,this.getHeight());
	}
 
 
	public void mouseDragged(MouseEvent e) {
		this.locationX=e.getXOnScreen();
		this.locationY=e.getYOnScreen();
		this.setLocation(this.locationX,this.locationY);
	}
	public void mouseMoved(MouseEvent e) {}
}
ma classe Cal contenant mon GridLayout dans un JPanel:
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
 
class Cal extends JPanel{
	Calendar calendar=new GregorianCalendar();
	private int jourC;
	private int jourAffiche;
	private JLabel jourGrille;
	private final String[]tabJour1={"Di","Li","Ma","Me","J","Ve","Sa"};
	private final String[]tabMois1={"janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"};
	private final Font fontJour=new Font("sherif",Font.ROMAN_BASELINE,10);
	public  Cal(){
		int [][]tab= tabCalendrier(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH));
		GridLayout grille=new GridLayout(6,7);
		setLayout(grille);
		int val0,val1,val2;
		String valeurJour="";
 
		for (val0=0;val0<7;val0++){
			valeurJour=tabJour1[val0];
			this.add(new JLabel(valeurJour));
		}
		for (val1=0;val1<6;val1++){
		for(val2=0;val2<7;val2++){
			jourC=tab[val1][val2];
			if (jourC==0){valeurJour=" 0";}
			else{
				if(jourC<10){valeurJour=Integer.toString(jourC)+" ";}
				else{
				valeurJour=Integer.toString(jourC);}
			}	
			jourGrille=new JLabel(valeurJour,SwingConstants.CENTER);
			jourGrille.setFont(fontJour);
			add(jourGrille);
		}	
		}
	}
 
	public int[][] tabCalendrier(int annee,int mois){
		int [][]tab=new int[6][7];
 
		calendar.set(Calendar.YEAR,annee);
		calendar.set(Calendar.MONTH, mois);
		calendar.set(Calendar.DAY_OF_MONTH,1 );
		int moisPresent=calendar.get(Calendar.MONTH);
 
		int i=0;
		do{
			jourC=calendar.get(Calendar.DAY_OF_MONTH);
			jourAffiche=calendar.get(Calendar.DAY_OF_WEEK);
			tab[i][jourAffiche-1]=jourC;
 
		if(jourAffiche==Calendar.SATURDAY)i++;
			calendar.add(Calendar.DAY_OF_MONTH,1);
		}while(moisPresent==calendar.get(Calendar.MONTH));
		return tab;
	}
}