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
| protected void paintComponent(Graphics g) {
// comme le composant n'est pas peint partout
// et qu'on modifie sa zone dessinable, on peint
// le composant avec la couleur du container parent
int w = getWidth(), h = getHeight();
Color parentBackground = getParent().getBackground();
g.setColor(parentBackground);
g.fillRect(0, 0, w, h);
Graphics2D g2d = (Graphics2D)g;
RenderingHints renderHints =
new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderHints.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHints(renderHints);
int round = (w > h ? h : w)/10;
if(bordure){
g.setColor(Color.black);
g.drawRoundRect(4, 4, w -9 , h-5,(int)(round*1.2),(int)(round*1.2));
}
/*Initial Graphics clip is the full bounds of the component:
*create a rounded clip LARGER than the compolor.r*/
RoundRectangle2D.Float r2d =
new RoundRectangle2D.Float(
5, 5, w -10 , h-6, round, round);
/*intersect this with the existing clip*/
g2d.clip(r2d);
super.paintComponent(g);
} |
Partager