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

53
LINES

< > BotCompany Repo | #1008596 // Custom layout manager, scrollable [WORKS]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (2329L/16K).

1  
!7
2  
3  
abstract sclass AbstractLayoutManager implements LayoutManager {
4  
  Dimension preferredSize = new Dimension(100, 100);
5  
  bool invalidate;
6  
7  
  public void addLayoutComponent(String name, Component comp) {
8  
    print("addLayoutComponent called");
9  
  }
10  
  public void removeLayoutComponent(Component comp) {
11  
    print("removeLayoutComponent called");
12  
  }
13  
  
14  
  public Dimension preferredLayoutSize(Container parent) {
15  
    print("preferredLayoutSize called (" + invalidate + ")");
16  
    layoutContainer(parent);
17  
    //validate(parent);
18  
    ret preferredSize;
19  
  }
20  
  
21  
  public Dimension minimumLayoutSize(Container parent) {
22  
    print("minimumLayoutSize called");
23  
    ret new Dimension(10, 10);
24  
  }
25  
  
26  
  void validate(Container parent) {
27  
    if (invalidate) {
28  
      invalidate = false;
29  
      layoutContainer(parent);
30  
    }
31  
  }
32  
}
33  
34  
p-substance {
35  
  JPanel panel = new JPanel(new AbstractLayoutManager {
36  
    public void layoutContainer(Container parent) {
37  
      print("layoutContainer called");
38  
      int y = 10;
39  
      for (Component c : parent.getComponents()) {
40  
        int h = c.getPreferredSize().height;
41  
        c.setBounds(10, y, 300, h);
42  
        y += h + 10;
43  
      }
44  
      preferredSize = componentsBoundingSize(parent, 10);
45  
    }
46  
  });
47  
  
48  
  for i to 10:
49  
    panel.add(jtextfield());
50  
  print("components added");
51  
    
52  
  showFrame(jscroll_centered(panel));
53  
}

Author comment

Began life as a copy of #1008593

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: #1008596
Snippet name: Custom layout manager, scrollable [WORKS]
Eternal ID of this version: #1008596/11
Text MD5: 35787cfa2c95322a8a8cde19ce8f3e13
Transpilation MD5: 03a1fe6123058aafec096f73bf064d94
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-25 14:21:40
Source code size: 1402 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 651 / 997
Version history: 10 change(s)
Referenced in: [show references]