Libraryless. Click here for Pure Java version (9218L/51K).
1 | // also works when using centering of the component, |
2 | // e.g. through jscroll_center_borderless |
3 | svoid onEnclosingScrollPaneResize(JComponent c, Runnable r) { |
4 | new OnEnclosingScrollPaneResize(c, r).install(); |
5 | } |
6 | |
7 | srecord noeq OnEnclosingScrollPaneResize(JComponent c, Runnable r) { |
8 | settable bool debug; |
9 | ComponentAdapter listener; |
10 | JViewport viewport; |
11 | |
12 | void install { |
13 | if (r == null) ret; |
14 | bindToComponent(c, -> { |
15 | viewport = optCast JViewport(getParent(getParent(c))); |
16 | if (viewport != null) { |
17 | listener = new ComponentAdapter { |
18 | public void componentResized(ComponentEvent e) { |
19 | if (debug) print("Viewport resized"); |
20 | pcallF(r); |
21 | } |
22 | }; |
23 | viewport.addComponentListener(listener); |
24 | if (debug) print("OnEnclosingScrollPaneResize installed"); |
25 | } |
26 | }, -> { |
27 | if (listener != null && viewport != null) { |
28 | viewport.removeComponentListener(listener); |
29 | if (debug) print("OnEnclosingScrollPaneResize removed"); |
30 | } |
31 | }); |
32 | } |
33 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035775 |
Snippet name: | onEnclosingScrollPaneResize |
Eternal ID of this version: | #1035775/9 |
Text MD5: | 48b82767f32d21051b724de869c139b0 |
Transpilation MD5: | 57a6e6d73d7c154f3cb3354e584ef2f9 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-07-23 22:47:04 |
Source code size: | 1074 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 79 / 147 |
Version history: | 8 change(s) |
Referenced in: | [show references] |