Java - Strange JTable HeaderRenderer problem

Discussion in 'Mac Programming' started by whitehexagon, Nov 20, 2008.

  1. whitehexagon macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #1
    This only fails under OSX.

    I have:

    Code:
    class ColorTableHeaderRenderer extends JLabel implements TableCellRenderer
    where I override the paint method to draw a custom colored box & font into the label.

    So for each table column I do something like this:

    Code:
    col.setHeaderRenderer(new ColorTableHeaderRenderer(getColorForColumn(colIndex)));
    At runtime this draws the text, but all the fillRect() statements seem to fail! However if I replace setColour and fillRect with setBackground and clearRect. Then when I scroll the table to the right. The newly revealed column header appears correct, and when I scroll the table left again, the first columns render correct.

    It seems like some strange painting optimization is going on with the headers that fillRect is being ignored, and also that the headers are not fully painted. As I mentioned this seems to OSX specific, the same code works fine under windows and linux.

    I also tried many variation with just tweaking attributes of the Label with the required color, eg the border, a custom drawn icon full of the color, the background, the foreground. In all cases it's as though the statements are being ignored. The colour being held in each renderer instance looks fine.

    Any tips?
     
  2. whitehexagon thread starter macrumors regular

    whitehexagon

    Joined:
    May 12, 2007
    #2
    bah, you can ignore the above. The problem was related to accidental use of alpha values in the colors being used for the setColor statements.
     

Share This Page