un scroll bar indésirable
Bonjour,
voilà mon problème : j'ai un JPanel qui contient un scrollbar et un autre Jpanel (Tracegrid) qui va servir pour dessiner un disque coloré
voilà le code de ma classe principale Trace
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
| class Trace extends JFrame{
JPanel principal ;
JScrollBar oneJScrollBar ;
TraceGrid g;
public Trace(){
super("testtracegrid");
this.principal = new JPanel();
this.principal.setLayout(new BorderLayout());
this.oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL,0,20,0,100);
this.g = new TraceGrid();
AdjustmentListener adjustmentListener = new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
// System.out.println("Adjusted: " + adjustmentEvent.getValue());
g.value = adjustmentEvent.getValue();
g.repaint();
}
};
oneJScrollBar.addAdjustmentListener(adjustmentListener);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,500);
principal.add(oneJScrollBar,BorderLayout.SOUTH);
principal.add(g, BorderLayout.CENTER);
this.setContentPane(principal);
g.repaint();
this.setVisible(true);
}
} |
et celui de Trcegrid
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
| public class TraceGrid extends JPanel{
int value = 0 ;
public TraceGrid(){
super();
}
public TraceGrid(double d, double e , int height , int width) {
super();
//super.setPreferredSize(new Dimension(width,height));
super.setBackground(new Color(201,201,214));
}
public void setvalue(int i ){
this.value = i ;
}
public void paintComponent(Graphics g) {
this.setBackground(new Color(201,201,214));
// System.out.println("value ="+value);
// System.out.println("largeur du Jpanel"+this.getWidth() +" hauteur du Jpanel "+ this.getHeight());
int i = (int) this.getWidth()/4 ;
int j = (int) this.getHeight()/4 ;
// System.out.println("i="+i +"j="+j);
if(this.value <20) g.setColor(Color.RED);
if(this.value <30 && this.value >19) g.setColor(Color.RED);
if( this.value >29 && this.value <40) g.setColor(Color.GREEN);
if(this.value >39 && this.value <50) g.setColor(Color.CYAN);
if(this.value >49 && this.value <60) g.setColor(Color.darkGray);
if(this.value >59 && this.value <70) g.setColor(Color.MAGENTA);
if(this.value >69 && this.value <80) g.setColor(Color.BLACK);
if(this.value >79 && this.value <90) g.setColor(Color.GREEN);
if(this.value > 89 && this.value <100) g.setColor(Color.YELLOW);
g.fillOval(i,j, this.getWidth()/2, this.getHeight()/2);
} |
le problème est que quand je déplace mon scroll bar , le disque change de couleur mais en haut il apparait une trace d'un autre scroll bar :calim2:, voilà je vous ai fait une capture d'écran
http://img198.imageshack.us/img198/1148/tracegrid.jpg
:cry: comment résoudre ce problème :merci: