import java.awt.*; import java.util.*; import java.util.List; import javax.swing.*; public class Testing extends JFrame { private final List<List<MyIcon>> map; public Testing() { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(1000, 500); setLocationRelativeTo(null); map = new ArrayList<List<MyIcon>>(); for (int i = 0; i < 25; i++) { List<MyIcon> iconList = new ArrayList<MyIcon>(); for (int j = 0; j < 25; j++) { iconList.add(new MyIcon()); } map.add(iconList); } JPanel panel = new JPanel(new GridLayout(0, 25)); for (List<MyIcon> list : map) { for (MyIcon myIcon : list) { JLabel carte = new JLabel(myIcon); panel.add(carte); } } add(new JScrollPane(panel)); } public static void main(final String args[]) { EventQueue.invokeLater(new Runnable() { public void run() { new Testing().setVisible(true); } }); } } class MyIcon implements Icon { private final Color color; public MyIcon() { final Random r = new Random(); color = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); } public void paintIcon(final Component c, final Graphics g, final int x, final int y) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(color); g.fillOval(x + 2, y + 2, getIconWidth() - 4, getIconHeight() - 4); } public int getIconWidth() { return 32; } public int getIconHeight() { return 64; } }