sclass StackLayouter extends F1<Container, Dimension> { Map<Component, Int> heights = weakHashMap(); int gap = 5; //int defaultHeight = 50; int preferredWidth = 300; bool maximizeIfSingleComponent = true; Dimension get(Container parent) { L<Component> l = getComponents(parent); Insets insets = unnullInsets(parent.getInsets()); Dimension size = parent.getSize(); ifdef StackLayouter_debug print("StackLayouter: n=" + l(l) + ", insets=" + insets + ", size=" + size); endifdef int y = insets.top; int width = size.width-insets.left-insets.right; for (Component c : l) { Int H; if (maximizeIfSingleComponent && l(l) == 1) { ifdef StackLayouter_debug print("StackLayouter maximizing!"); endifdef H = size.height-insets.bottom-y; } else H = heights.get(c); int h = H != null ? H : c.getPreferredSize().height; c.setBounds(insets.left, y, width, h); y += h+gap; ifdef StackLayouter_debug print("StackLayouter: y=" + y + ", h=" + h); endifdef } // return preferred size (hm.) ret new Dimension(preferredWidth, max(50 /* XXX */, y+insets.bottom-gap)); }; }
Began life as a copy of #1022754
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1022755 |
Snippet name: | StackLayouter - with choosable height per component |
Eternal ID of this version: | #1022755/20 |
Text MD5: | c126dab39c660edfbc0437f1f3760345 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-06 22:25:10 |
Source code size: | 1255 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 308 / 782 |
Version history: | 19 change(s) |
Referenced in: | [show references] |