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).

svoid onUpdate(JComponent c, Runnable r) {
  onUpdate(c, (O) r);
}

svoid onUpdate(JTextComponent c, IVF1<S> r) {
  if (c == null || r == null) ret;
  c.getDocument().addDocumentListener(runnableToDocumentListener(-> r.get(c.getText())));
}

// legacy signature
svoid onUpdate(JComponent c, O r) {
  if (c cast JTextComponent)
    c.getDocument().addDocumentListener(runnableToDocumentListener(toRunnable(r)));
  else if (c cast ItemSelectable) // JCheckBox and others
    c.addItemListener(new ItemListener {
      public void itemStateChanged(ItemEvent e) {
        pcallF(r);
      }
    });
  else if (c cast JSpinner)
    onChange(c, r);
  else
    print("Warning: onUpdate doesn't know " + getClassName(c));
}

static void onUpdate(L<? extends JComponent> l, O r) {
  for (JComponent c : l)
    onUpdate(c, r);
}

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: 722 / 798
Version history: 6 change(s)
Referenced in: #1006125 - onUpdateAndNow (for JTextComponent, JCheckBox and others)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)