static JScrollPane jscroll_verticalExtend(final Component c) { ret swing(func -> JScrollPane { new JScrollPane sp; sp.setViewport(new JViewport { protected LayoutManager createLayoutManager() { ret new ViewportLayout { public void layoutContainer(Container parent) { JViewport vp = (JViewport)parent; Component view = vp.getView(); Scrollable scrollableView = null; if (view == null) { return; } else if (view instanceof Scrollable) { scrollableView = (Scrollable) view; } Insets insets = vp.getInsets(); Dimension viewPrefSize = view.getPreferredSize(); Dimension vpSize = vp.getSize(); Dimension extentSize = vp.toViewCoordinates(vpSize); Dimension viewSize = new Dimension(viewPrefSize); if (scrollableView != null) { if (scrollableView.getScrollableTracksViewportWidth()) { viewSize.width = vpSize.width; } if (scrollableView.getScrollableTracksViewportHeight()) { viewSize.height = vpSize.height; } } // XXX viewSize.height = max(viewSize.height, vpSize.height); // YYY Point viewPosition = vp.getViewPosition(); /* If the new viewport size would leave empty space to the * right of the view, right justify the view or left justify * the view when the width of the view is smaller than the * container. */ if (scrollableView == null || vp.getParent() == null || vp.getParent().getComponentOrientation().isLeftToRight()) { if ((viewPosition.x + extentSize.width) > viewSize.width) { viewPosition.x = Math.max(0, viewSize.width - extentSize.width); } } else { if (extentSize.width > viewSize.width) { viewPosition.x = viewSize.width - extentSize.width; } else { viewPosition.x = Math.max(0, Math.min(viewSize.width - extentSize.width, viewPosition.x)); } } /* If the new viewport size would leave empty space below the * view, bottom justify the view or top justify the view when * the height of the view is smaller than the container. */ if ((viewPosition.y + extentSize.height) > viewSize.height) { viewPosition.y = Math.max(0, viewSize.height - extentSize.height); } /* If we haven't been advised about how the viewports size * should change wrt to the viewport, i.e. if the view isn't * an instance of Scrollable, then adjust the views size as follows. * * If the origin of the view is showing and the viewport is * bigger than the views preferred size, then make the view * the same size as the viewport. */ if (scrollableView == null) { if ((viewPosition.x == 0) && (vpSize.width > viewPrefSize.width)) { viewSize.width = vpSize.width; } if ((viewPosition.y == 0) && (vpSize.height > viewPrefSize.height)) { viewSize.height = vpSize.height; } } vp.setViewPosition(viewPosition); vp.setViewSize(viewSize); } }; // new ViewportLayout } }); // new JViewport sp.setViewportView(c); ret sp; }); }
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: | 381 / 417 |
Version history: | 7 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |