Libraryless. Click here for Pure Java version (4862L/27K).
1 | static <A> void setComboBoxItems_notifyListeners(JComboBox<A> cb, Cl<A> items) { |
2 | if (cb != null) swing { |
3 | if (eq(getComboBoxItems(cb), items)) ret; // nothing to do |
4 | |
5 | var sel = getSelectedItem_typed(cb); |
6 | setComboBoxItems(cb, items); |
7 | var item = getSelectedItem_typed(cb); |
8 | if (!eq(sel, item)) { |
9 | // restore old selection if possible |
10 | if (sel != null && contains(items, sel)) |
11 | setSelectedItem(cb, sel); |
12 | else { |
13 | //printVars("combobox", +sel, +item); |
14 | |
15 | // force onChange event(s) (need to use two events) |
16 | setSelectedItem(cb, (A) null); |
17 | setSelectedItem(cb, item); |
18 | } |
19 | } |
20 | } |
21 | } |
Began life as a copy of #1009086
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033917 |
Snippet name: | setComboBoxItems_notifyListeners - fire a change event when a different item is selected afterwards |
Eternal ID of this version: | #1033917/9 |
Text MD5: | eee6ae28a8cadf69d053a879993056b5 |
Transpilation MD5: | bc52b17668aef67e2b81107d16a8d60f |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-13 16:33:31 |
Source code size: | 680 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 149 / 245 |
Version history: | 8 change(s) |
Referenced in: | [show references] |