// background color is set with setBackground sclass JMultiColorBar > JComponentWithChangeListeners { class Entry { settable double value; settable Color color; settable S text; } L entries = notifyingList(l0 repaint); settableWithVar double max = 100; settable L defaultColors = ll(Color.red, Color.blue); swappable Color defaultColor(int index) { ret getCyclic(defaultColors, index); } void addEntry aka add(S text, double value) { entries.add(new Entry().+value.color(defaultColor(l(entries)))); } void addEntry aka add(double value, Color color) { entries.add(new Entry().+value.+color); } *() { 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, x+1, 0, x2-x, h, e.color); x = x2; } } }