Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1008612 // gridLayoutPanel_trackWidth_evenlySpacedCols

JavaX fragment (include)

static JPanel gridLayoutPanel_trackWidth_evenlySpacedCols(final int cols) {
  ret customLayoutPanel_trackWidth(func(Container parent) {
    int gap = 10;
    Dimension size = parent.getSize();
    int w = max(100, size.width)-gap*2;
    int y = gap;
    LL<Component> rows = groupInFixedSizeRows(parent.getComponents(), cols);
    new L<Int> colWidths;
    for i to cols:
      colWidths.add((i+1)*w/cols-i*w/cols);
      
    for (L<Component> row : rows) {
      int h = 0, x = gap;
      for (Component c : row) h = max(h, c.getPreferredSize().height);
      for i over row: {
        row.get(i).setBounds(x, y, colWidths.get(i)-gap, h);
        x += colWidths.get(i);
      }
      y += h + gap;
    }
    
    ret componentsBoundingSize(parent, gap);
  });
}

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: #1008612
Snippet name: gridLayoutPanel_trackWidth_evenlySpacedCols
Eternal ID of this version: #1008612/1
Text MD5: d1150e1fa731ac711f857e31b4745d4f
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-25 19:09:01
Source code size: 786 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 571 / 573
Referenced in: [show references]