// background color is set with setBackground sclass JMultiColorBar > JComponentWithChangeListeners { class Entry { settable double value; settable Color color; } L entries = notifyingList(l0 repaint); settableWithVar double max = 100; void addEntry(double value, Color color) { entries.add(new Entry().+value.+color); } *() { setForeground(Color.red); varMax().onChange(l0 repaint); jMinSize(50, 10, this); } public void paintComponent(Graphics g) { super.paintComponent(g); // paint background int w = getWidth(), h = getHeight(); int x = 0; for (e : entries) { int x2 = main max(x, iround(w*clampZeroToOne(doubleRatio(e.value, max)))); if (x2 > x) fillRect(g, x2+1, 0, x2-x, h, e.color); x = x2; } } }