1 | static JScrollPane jscroll_verticalExtend(final Component c) { |
2 | ret swing(func -> JScrollPane { |
3 | new JScrollPane sp; |
4 | sp.setViewport(new JViewport { |
5 | protected LayoutManager createLayoutManager() { |
6 | ret new ViewportLayout { |
7 | public void layoutContainer(Container parent) { |
8 | JViewport vp = (JViewport)parent; |
9 | Component view = vp.getView(); |
10 | Scrollable scrollableView = null; |
11 | |
12 | if (view == null) { |
13 | return; |
14 | } |
15 | else if (view instanceof Scrollable) { |
16 | scrollableView = (Scrollable) view; |
17 | } |
18 | |
19 | Insets insets = vp.getInsets(); |
20 | Dimension viewPrefSize = view.getPreferredSize(); |
21 | Dimension vpSize = vp.getSize(); |
22 | Dimension extentSize = vp.toViewCoordinates(vpSize); |
23 | Dimension viewSize = new Dimension(viewPrefSize); |
24 | |
25 | if (scrollableView != null) { |
26 | if (scrollableView.getScrollableTracksViewportWidth()) { |
27 | viewSize.width = vpSize.width; |
28 | } |
29 | if (scrollableView.getScrollableTracksViewportHeight()) { |
30 | viewSize.height = vpSize.height; |
31 | } |
32 | } |
33 | |
34 | // XXX |
35 | viewSize.height = max(viewSize.height, vpSize.height); |
36 | // YYY |
37 | |
38 | Point viewPosition = vp.getViewPosition(); |
39 | |
40 | /* If the new viewport size would leave empty space to the |
41 | * right of the view, right justify the view or left justify |
42 | * the view when the width of the view is smaller than the |
43 | * container. |
44 | */ |
45 | if (scrollableView == null || |
46 | vp.getParent() == null || |
47 | vp.getParent().getComponentOrientation().isLeftToRight()) { |
48 | if ((viewPosition.x + extentSize.width) > viewSize.width) { |
49 | viewPosition.x = Math.max(0, viewSize.width - extentSize.width); |
50 | } |
51 | } else { |
52 | if (extentSize.width > viewSize.width) { |
53 | viewPosition.x = viewSize.width - extentSize.width; |
54 | } else { |
55 | viewPosition.x = Math.max(0, Math.min(viewSize.width - extentSize.width, viewPosition.x)); |
56 | } |
57 | } |
58 | |
59 | /* If the new viewport size would leave empty space below the |
60 | * view, bottom justify the view or top justify the view when |
61 | * the height of the view is smaller than the container. |
62 | */ |
63 | if ((viewPosition.y + extentSize.height) > viewSize.height) { |
64 | viewPosition.y = Math.max(0, viewSize.height - extentSize.height); |
65 | } |
66 | |
67 | /* If we haven't been advised about how the viewports size |
68 | * should change wrt to the viewport, i.e. if the view isn't |
69 | * an instance of Scrollable, then adjust the views size as follows. |
70 | * |
71 | * If the origin of the view is showing and the viewport is |
72 | * bigger than the views preferred size, then make the view |
73 | * the same size as the viewport. |
74 | */ |
75 | if (scrollableView == null) { |
76 | if ((viewPosition.x == 0) && (vpSize.width > viewPrefSize.width)) { |
77 | viewSize.width = vpSize.width; |
78 | } |
79 | if ((viewPosition.y == 0) && (vpSize.height > viewPrefSize.height)) { |
80 | viewSize.height = vpSize.height; |
81 | } |
82 | } |
83 | vp.setViewPosition(viewPosition); |
84 | vp.setViewSize(viewSize); |
85 | } |
86 | }; // new ViewportLayout |
87 | } |
88 | }); // new JViewport |
89 | sp.setViewportView(c); |
90 | ret sp; |
91 | }); |
92 | } |
Began life as a copy of #1006014
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1014109 |
Snippet name: | jscroll_verticalExtend - extends component's height to at least viewport height? (forgot what it does) |
Eternal ID of this version: | #1014109/8 |
Text MD5: | 1bdb1fead7932d72c95100390e80aa6b |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-07 01:22:44 |
Source code size: | 3881 bytes / 92 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 382 / 419 |
Version history: | 7 change(s) |
Referenced in: | [show references] |