JTable cells not rendering shapes properly

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2010-06-10T12:07:19Z Indexed on 2010/06/10 12:13 UTC
Read the original article Hit count: 217

Filed under:
|
|

I'm trying to render my JTable cells with a subclassed JPanel and the cells should appear as coloured rectangles with a circle drawn on them. When the table displays initially everything looks OK but then when a dialog or something is displayed over the cells when it is removed the cells that have been covered do not rendered properly and the circles are broken up etc. I then have to move the scroll bar or extend the window to get them to redraw properly.

The paintComponent method of the component I'm using to render the cells is below:

protected void paintComponent(Graphics g) { 
    setOpaque(true);
    super.paintComponent(g); 
    Graphics2D g2d = (Graphics2D) g;
    GradientPaint gradientPaint = new GradientPaint(new Point2D.Double(0, 0),    Color.WHITE, new Point2D.Double(0,
            getHeight()), paintRatingColour);
    g2d.setPaint(gradientPaint);
    g2d.fillRect(0, 0, getWidth(), getHeight());

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    Rectangle clipBounds = g2d.getClipBounds();
    int x = new Double(clipBounds.getWidth()).intValue() - 15;
    int y = (new Double(clipBounds.getHeight()).intValue() / 2) - 6;

    if (level != null) { 
        g2d.setColor(iconColour);
        g2d.drawOval(x, y, width, height);
        g2d.fillOval(x, y, width, height); 
    } 
}

© Stack Overflow or respective owner

Related posts about java

Related posts about swing