Libraryless. Click here for Pure Java version (8671L/49K).
// use setForeground and setBackground for the colors // TODO: repaint more sparingly sclass JColorBar > JComponentWithChangeListeners { settableWithVar double value; settableWithVar double max = 100; *() { setForeground(Color.red); for (var : ll(varValue(), varMax())) var.onChange(l0 repaint); jMinSize(50, 10, this); } public void paintComponent(Graphics g) { super.paintComponent(g); // paint background int w = getWidth(), h = getHeight(); fillRect(g, 0, 0, iround(w*clampZeroToOne(doubleRatio(value, max))), h, getForeground()); } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035303 |
Snippet name: | JColorBar |
Eternal ID of this version: | #1035303/8 |
Text MD5: | ccd658b46e82643bd693d7dc2be6e178 |
Transpilation MD5: | e1f7bf540dd73e221c161009218f9f1b |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-04-29 04:22:43 |
Source code size: | 602 bytes / 19 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 157 / 252 |
Version history: | 7 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) #1036081 - JMultiColorBar [OK] |