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

16
LINES

< > BotCompany Repo | #1022588 // jThreadedButton - make JButton running in new thread & holding button instance

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

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

1  
// action can be Runnable or a function name
2  
static JButton jThreadedButton(S text, O action) {
3  
  ret swing(func -> JButton {
4  
    S text2 = dropPrefix("[disabled] ", text);
5  
    JButton btn = basicJButton(text2);
6  
    if (l(text2) < l(text)) btn.setEnabled(false);
7  
    btn.setToolTipText(btn.getText());
8  
    if (action != null)
9  
      btn.addActionListener(actionListenerInNewThread(action, btn));
10  
    ret btn;
11  
  });
12  
}
13  
14  
static JButton jThreadedButton(S text, Runnable action) {
15  
  ret jThreadedButton(text, (O) action);
16  
}

Author comment

Began life as a copy of #1003297

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022588
Snippet name: jThreadedButton - make JButton running in new thread & holding button instance
Eternal ID of this version: #1022588/3
Text MD5: fd8a9bbb9b5ca4531f41be9c401682e0
Transpilation MD5: 3a40e720bc4d2a253502fc93438cd095
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-28 15:34:26
Source code size: 532 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 358 / 458
Version history: 2 change(s)
Referenced in: [show references]