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)

ifndef Android

sbool setText_opt = true; // optimize by calling getText first

static <A extends JTextComponent> A setText(A c, O text) {
  setText((JComponent) c, text);
  ret c;
}

static <A extends JComboBox> A setText(final A c, O text) {
  // only for editable combo boxes at this point
  fS s = strUnnull(text);
  swing {
    c.getEditor().setItem(s);
  }
  ret c;
}

svoid setText(JLabel c, O text) {
  setText((JComponent) c, text);
}

static JButton setText(JButton c, O text) {
  setText((JComponent) c, jlabel_textAsHTML_center_ifNeeded(strUnnull(text)));
  ret c;
}

static <A extends JComponent> A setText(final A c, O text) {
  if (c == null) null;
  final S s = strUnnull(text);
  swing {
    if (!setText_opt || neq(callOpt(c, "getText"), s))
      call(c, "setText", s);
  }
  ret c;
}

endifndef

ifdef Android
svoid setText() {} // dummy
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: 732 / 725
Version history: 24 change(s)
Referenced in: [show references]