Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

19
LINES

< > BotCompany Repo | #1035303 // JColorBar

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (8671L/49K).

1  
// use setForeground and setBackground for the colors
2  
// TODO: repaint more sparingly
3  
sclass JColorBar > JComponentWithChangeListeners {
4  
  settableWithVar double value;
5  
  settableWithVar double max = 100;
6  
  
7  
  *() {
8  
    setForeground(Color.red);
9  
    for (var : ll(varValue(), varMax()))
10  
      var.onChange(l0 repaint);
11  
    jMinSize(50, 10, this);
12  
  }
13  
14  
  public void paintComponent(Graphics g) {
15  
    super.paintComponent(g); // paint background
16  
    int w = getWidth(), h = getHeight();
17  
    fillRect(g, 0, 0, iround(w*clampZeroToOne(doubleRatio(value, max))), h, getForeground());
18  
  }
19  
}

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: 158 / 255
Version history: 7 change(s)
Referenced in: [show references]