Libraryless. Click here for Pure Java version (9473L/52K).
1  | // Don't call add/remove directly - use addComponent/removeComponent  | 
2  | static abstract class DynamicStack extends JPanel {
 | 
3  | settable int spacing = 10;  | 
4  | bool useFiller;  | 
5  | |
6  |   *() { this(true); }
 | 
7  | |
8  |   *(bool useFiller) {
 | 
9  | super(new GridBagLayout);  | 
10  | this.useFiller = useFiller;  | 
11  | _addFiller();  | 
12  | }  | 
13  | |
14  | abstract GridBagConstraints _componentConstraints();  | 
15  | abstract GridBagConstraints _fillerConstraints();  | 
16  | |
17  |   void _addFiller {
 | 
18  | if (useFiller) add(jrigid(), _fillerConstraints());  | 
19  | }  | 
20  | |
21  |   void addComponent(final Component c) {
 | 
22  | addComponents(ll(c));  | 
23  | }  | 
24  | |
25  |   void addComponents(Cl<? extends Component> l) swing {
 | 
26  | fOr (Component c : l)  | 
27  | if (c.getParent() != this)  | 
28  | add(c, _componentConstraints(), getComponentCount()-(useFiller ? 1 : 0));  | 
29  | revalidate();  | 
30  | }  | 
31  | |
32  |   void setComponents(Cl<? extends Component> l) {
 | 
33  | removeAll();  | 
34  | _addFiller();  | 
35  | addComponents(l);  | 
36  | }  | 
37  | |
38  |   void clearComponents() {
 | 
39  | setComponents(null);  | 
40  | }  | 
41  | |
42  |   void removeComponent(Component c) swing {
 | 
43  |     if (c != null) {
 | 
44  | remove(c);  | 
45  | revalidate();  | 
46  | }  | 
47  | }  | 
48  | |
49  |   int numComponents() { ret countComponents()-1; }
 | 
50  |   L<Component> components() {
 | 
51  | ret dropLast(main getComponents(this));  | 
52  | }  | 
53  | |
54  |   bool isEmpty() { ret numComponents() == 0; }
 | 
55  | }  | 
Began life as a copy of #1015034
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: | #1015164 | 
| Snippet name: | DynamicStack - base class of DynamicHStack/DynamicVStack | 
| Eternal ID of this version: | #1015164/15 | 
| Text MD5: | 1c73c0e7c5e66bbe063601cccd5e96a1 | 
| Transpilation MD5: | 880f75f3d3762ce5ce70e5c94a6fbd49 | 
| Author: | stefan | 
| Category: | javax / gui | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2022-10-26 16:41:50 | 
| Source code size: | 1312 bytes / 55 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 738 / 1461 | 
| Version history: | 14 change(s) | 
| Referenced in: | [show references] |