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

29
LINES

< > BotCompany Repo | #1003287 // onUpdate (for JTextComponent, JCheckBox and others)

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

Libraryless. Click here for Pure Java version (7886L/45K).

1  
svoid onUpdate(JComponent c, Runnable r) {
2  
  onUpdate(c, (O) r);
3  
}
4  
5  
svoid onUpdate(JTextComponent c, IVF1<S> r) {
6  
  if (c == null || r == null) ret;
7  
  c.getDocument().addDocumentListener(runnableToDocumentListener(-> r.get(c.getText())));
8  
}
9  
10  
// legacy signature
11  
svoid onUpdate(JComponent c, O r) {
12  
  if (c cast JTextComponent)
13  
    c.getDocument().addDocumentListener(runnableToDocumentListener(toRunnable(r)));
14  
  else if (c cast ItemSelectable) // JCheckBox and others
15  
    c.addItemListener(new ItemListener {
16  
      public void itemStateChanged(ItemEvent e) {
17  
        pcallF(r);
18  
      }
19  
    });
20  
  else if (c cast JSpinner)
21  
    onChange(c, r);
22  
  else
23  
    print("Warning: onUpdate doesn't know " + getClassName(c));
24  
}
25  
26  
static void onUpdate(L<? extends JComponent> l, O r) {
27  
  for (JComponent c : l)
28  
    onUpdate(c, r);
29  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003287
Snippet name: onUpdate (for JTextComponent, JCheckBox and others)
Eternal ID of this version: #1003287/7
Text MD5: 11eaadc3cc2cf967835f8aa140f62a07
Transpilation MD5: 6644fb514fbcfe3d0c57b665c2374206
Author: stefan
Category: javax swing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-01 22:57:51
Source code size: 846 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 596 / 667
Version history: 6 change(s)
Referenced in: [show references]