Salut à tous,
J'ai un petit souci au niveau de l'affichage d'une fenetre.
En effet, j'ai défini un classe JGraph2D héritant d'un JPanel et contenant un second JPanel puis une classe de Test afin de vérifier mon résultat.
Cependant, lorsque je lance mon application, je peux observer un bandeau transparent entre le bord de ma JFrame et le second JPanel contenu dans le JGraph2D.
Je pense que je dois me perdre dans la redéfinition des méthodes paint(Graphics g), paintComponents(Graphics g) et paintComponent(Graphics g).
Si vous avez une petite idée ....
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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import javax.swing.*;
 
import java.awt.*;
 
import java.util.*;
 
 
 
public class JGraph2D extends JPanel
 
{
 
    protected int hPanel, lPanel ;          // longueur et largeur du panel general
 
    protected int hGraph, lGraph ;          // longueur et largeur du panel du graphe
 
    protected int hEspace, lEspace ;        // gap horizontal et vertical
 
 
 
    protected JPanel panelGraph ;           // le panel contenant le graphe
 
 
 
    protected ArrayList dataX, dataY ;      // les donnees representees sur le graphe      
 
 
 
    protected int numVoie ;                 // le numero de la voie concernee
 
 
 
    /** Creates a new instance of JGraph2D */
 
    public JGraph2D(int l, int h, int i) 
 
    {
 
        super(null);                        // on cree le panel pere avec un layout null
 
        this.numVoie = i ;                  // on stocke le numero de voie
 
 
 
        this.hPanel = h ;                   // la longueur du panel
 
        this.lPanel = l ;                   // la largeur du panel
 
 
 
        this.setSize(this.lPanel,this.hPanel);
        this.setBorder(BorderFactory.createEtchedBorder());
 
 
 
        this.hGraph = (int)(0.8*this.hPanel) ;
 
        this.lGraph = (int)(0.8*this.lPanel) ;
 
        this.hEspace = (int)(0.1*this.hPanel) ;
 
        this.lEspace = (int)(0.1*this.lPanel) ;
 
 
 
        this.panelGraph = new JPanel(null);
 
        this.panelGraph.setBackground(Color.white);
 
        this.panelGraph.setBounds(this.lEspace,this.hEspace,this.lGraph, this.hGraph);
 
        this.panelGraph.setBorder(BorderFactory.createEtchedBorder());
 
 
 
 
 
        this.add(this.panelGraph);
 
    }
 
 
 
    public void tracerGrille(Graphics g)
 
    {
 
        // On definit la couleur de fond en gris
 
        g.setColor(Color.gray);
 
 
 
        // En horizontal
 
        g.drawLine(lEspace,hEspace+3*hGraph/4,lEspace+lGraph-2,hEspace+3*hGraph/4); // Au premier quart
 
        g.drawLine(lEspace,hEspace+hGraph/2,lEspace+lGraph-2,hEspace+hGraph/2); // Au milieu
 
        g.drawLine(lEspace,hEspace+hGraph/4,lEspace+lGraph-2,hEspace+hGraph/4); // Au troisieme quart
 
 
 
        // En vertical
 
        g.drawLine(lEspace+lGraph/4,hEspace+1,lEspace+lGraph/4,hEspace+hGraph-1); // Trace de la graduation au premier quart
 
        g.drawLine(lEspace+lGraph/2,hEspace+1,lEspace+lGraph/2,hEspace+hGraph-1); // Trace de la graduation au milieu
 
        g.drawLine(lEspace+3*lGraph/4,hEspace+1,lEspace+3*lGraph/4,hEspace+hGraph-1); // Trace de la graduation au troisieme quart
 
    }
 
 
 
    public void paint(Graphics g)
 
    {
    	  super.paintComponents(g);
 
 
 
        tracerGrille(g);
 
        tracerLegende(g);
 
 
 
    }
 
 
 
    public void tracerLegende(Graphics g)
 
    {
 
        g.drawRect(2,2,50,10);
 
    }
 
 
 
 
 
 
 
 
 
}
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
57
58
59
60
61
62
63
64
65
import javax.swing.*;
 
import java.awt.*;
 
 
 
public class FenetreTest extends JFrame
 
{
 
    private JGraph2D graph ;
 
 
 
    public FenetreTest() 
 
    {
 
        super();
 
 
 
        build();
 
    }
 
 
 
    public void build()
 
    {
 
        this.setSize(300,300);
 
        this.setLocationRelativeTo(null);
 
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 
 
 
        this.add(new JGraph2D(250,100,0));
 
 
 
    }
 
 
 
    public void paint(Graphics g)
 
    {
 
        // On dessine tous les composants de l'interface
 
        paintComponents(g);
 
    }
 
    public static void main(String[] args)
    {
    	FenetreTest f = new FenetreTest();
    	f.setVisible(true);
    }
 
}