tags:

views:

280

answers:

2
A: 

Just make each of the colored bars themselves panels with a different background color. Don't forget to make the panels explicitly opaque with setOpaque(true) - panels are transparent by default transparent in most look and feels.

A note on aesthetics; I would start with the first line in each group shaded differently.

Software Monkey
+3  A: 

Try using a JTable and then alternating the colors of the row. This way you can write a generic JComponent (AlternatingColorTable) and use it just like a regular JTable in those 4 panels.

Something like this maybe:

public class AlternatingColorTable extends JTable {

public AlternatingColorTable () {
    super();
}

public AlternatingColorTable(TableModel tableModel) {
    super(tableModel);
}

/** Extends the renderer to alternate row colors */
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
    Component returnComp = super.prepareRenderer(renderer, row, col);

    Color alternateColor = Color.GRAY;
    Color mainColor = Color.DARK_GRAY;

    if (!returnComp.getBackground().equals(getSelectionBackground())) {
        Color background = (row % 2 == 0 ? alternateColor : mainColor );
        returnComp.setBackground(background);
        background = null;
    }
    return returnComp;
}

}

Herminator
+1 Well, to me, the background color shifting is to be done in the TableCellRenderer, but it's only a matter of choice
Riduidel
I think the prepareRenderer() method is the perfect place for this since you only need to do it in one place. Otherwise you need a custom renderer for the String column and the RadioButton columns. See http://tips4java.wordpress.com/2010/01/24/table-row-rendering/ for my two cents.
camickr