Как насчет этого примера
package test;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class PanelBG {
JFrame f;
public PanelBG() {
f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int nRows = 3;
int nColumns = 4;
int cellSize = 50;
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(new GridLayout(nRows, nColumns));
fieldPanel.setMaximumSize(new Dimension(nColumns*cellSize, nRows*cellSize));
Color colors[]={
new Color(115, 114, 83),
new Color(120, 130, 83),
new Color(140, 140, 83),
new Color(160, 180, 83),
new Color(170, 190, 83),
new Color(80, 190, 73),
new Color(100, 120, 83),
new Color(150, 240, 83),
new Color(180, 150, 83),
new Color(210, 190, 83),
new Color(230, 11, 83),
new Color(255, 255, 255)
};
for (int i=1; i<=nRows; i++) {
for (int j=1; j<=nColumns; j++) {
//JButton btn = new JButton("<html><span style='color:#000000; font-size: 11pt;'>"
// + label.getText() + "</span></html>");
//btn.setPreferredSize(new Dimension(cellSize, cellSize));
//btn.setHorizontalTextPosition(SwingConstants.LEFT);
//btn.setBackground(new Color(54,36,5));
//fieldPanel.add(btn);
JPanel p = new JPanel();
p.setPreferredSize(new Dimension(cellSize, cellSize));
JLabel l = new JLabel("Jlabel");
p.add(l);
p.setBackground(colors[i*j-1]);
fieldPanel.add(p);
}
}
f.getContentPane().add(fieldPanel);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
new PanelBG();
}
}