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

42
LINES

< > BotCompany Repo | #1003310 // setText - more flexible shorthand for JTextComponent/JLabel/JButton.setText() - uses AWT thread (and waits)

JavaX fragment (include)

1  
ifndef Android
2  
3  
sbool setText_opt = true; // optimize by calling getText first
4  
5  
static <A extends JTextComponent> A setText(A c, O text) {
6  
  setText((JComponent) c, text);
7  
  ret c;
8  
}
9  
10  
static <A extends JComboBox> A setText(final A c, O text) {
11  
  // only for editable combo boxes at this point
12  
  fS s = strUnnull(text);
13  
  swing {
14  
    c.getEditor().setItem(s);
15  
  }
16  
  ret c;
17  
}
18  
19  
svoid setText(JLabel c, O text) {
20  
  setText((JComponent) c, text);
21  
}
22  
23  
static JButton setText(JButton c, O text) {
24  
  setText((JComponent) c, jlabel_textAsHTML_center_ifNeeded(strUnnull(text)));
25  
  ret c;
26  
}
27  
28  
static <A extends JComponent> A setText(final A c, O text) {
29  
  if (c == null) null;
30  
  final S s = strUnnull(text);
31  
  swing {
32  
    if (!setText_opt || neq(callOpt(c, "getText"), s))
33  
      call(c, "setText", s);
34  
  }
35  
  ret c;
36  
}
37  
38  
endifndef
39  
40  
ifdef Android
41  
svoid setText() {} // dummy
42  
endifdef

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1003310
Snippet name: setText - more flexible shorthand for JTextComponent/JLabel/JButton.setText() - uses AWT thread (and waits)
Eternal ID of this version: #1003310/25
Text MD5: 22b576e3c5c912b1430e00cd41aa1034
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-24 14:02:51
Source code size: 907 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 837 / 837
Version history: 24 change(s)
Referenced in: [show references]