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

38
LINES

< > BotCompany Repo | #1014701 // showFormTitled (+ showForm_makePanel) - show input form [Swing, v1 with hvgrid]

JavaX fragment (include)

1  
//please include function withMargin.
2  
3  
static int showForm_defaultGap = 4;
4  
5  
static JPanel showFormTitled(fS title, fO... _parts) {
6  
  ret swing(func -> JPanel {
7  
    final new Var<JFrame> frame;
8  
    JPanel panel = showForm_makePanel(frame, _parts);
9  
    frame.set(handleEscapeKey(minFrameWidth(showPackedFrame(title, withMargin(panel)), 400)));
10  
    ret panel;
11  
  });
12  
}
13  
14  
static JPanel showForm_makePanel(final Var<JFrame> frame, O... _parts) {
15  
  new L<L> l;
16  
  L parts = asList(_parts);
17  
  Runnable submit = null;
18  
  for (int i = 0; i < l(parts); i++) {
19  
    final O o = parts.get(i), next = get(parts, i+1);
20  
    if (o instanceof Component || o instanceof S || next instanceof Component) { // smartAdd accepts strings
21  
      l.add(ll(o == null ? new JPanel : o, next));
22  
      if (next instanceof JButton && submit == null)
23  
        submit = r { ((JButton) next).doClick() };
24  
      i++;
25  
    } else if (isRunnable(o))
26  
      l.add(ll(null, jbutton(showFormSubmitButtonName(), submit = r {
27  
        O result = call(o);
28  
        if (neq(Boolean.FALSE, result))
29  
          disposeFrame(frame.get());
30  
      })));
31  
    else print("showForm: Unknown element type: " + getClassName(o));
32  
  }
33  
  JPanel panel = hvgrid((L) l, showForm_defaultGap);
34  
  if (submit != null)
35  
    for (JTextField textField : childrenOfType(panel, JTextField.class))
36  
      onEnter(textField, submit);
37  
  ret panel;
38  
}

Author comment

Began life as a copy of #1004442

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: #1014701
Snippet name: showFormTitled (+ showForm_makePanel) - show input form [Swing, v1 with hvgrid]
Eternal ID of this version: #1014701/1
Text MD5: 5405cf81dec6cede53a25c9409fdc411
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-30 17:24:40
Source code size: 1399 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 377 / 426
Referenced in: [show references]