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

55
LINES

< > BotCompany Repo | #1020846 // fillJTabs - fill JTabbedPane

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (6836L) is out of date.

1  
// x = names and components interleaving.
2  
// or just components.
3  
// or just names.
4  
// also, first element can be index of tab to open at start
5  
// also, SUPER short demo syntax: jtabs(3)
6  
// also, you can pass a Collection containing the elements
7  
static JTabbedPane fillJTabs(final JTabbedPane tabs, fO... _x) {
8  
  if (tabs == null) null;
9  
  clearTabs(tabs);
10  
  O[] x = flattenArray2(_x);
11  
  ifdef fillJTabs_debug
12  
  print("fillJTabs length=" + l(_x) + " => " + l(x));
13  
  endifdef
14  
  int idx = 0;
15  
  if (get(x, 0) instanceof Int) {
16  
    idx = asInt(get(x, 0));
17  
    x = dropFirst(x);
18  
    if (empty(x)) {
19  
      x = arrayrep(null, idx);
20  
      idx = 0;
21  
    }
22  
  }
23  
  int n = 0;
24  
  for (int i = 0; i < l(x); i++) {
25  
    ++n;
26  
    
27  
    // is it a component?
28  
    O o = x[i];
29  
    if (isComponentOrSwingable(o))
30  
      addTab(tabs, "Tab " + n, wrap(o));
31  
    else {
32  
      // assume it's a tab name, optionally followed by a component
33  
      S toolTip = "";
34  
      
35  
      // WithToolTip<S> is ok (WithToolTip<Component> not yet supported)
36  
      if (o cast WithToolTip) {
37  
        toolTip = o.toolTip();
38  
        o = o!;
39  
      }
40  
      S name = str(or(o, "Tab " + n));
41  
      ifdef fillJTabs_debug
42  
      print("tab " + i + ": " + name);
43  
      endifdef
44  
      Component c;
45  
      if (isComponentOrSwingable(get(x, i+1)))
46  
        c = wrap(get(x, ++i));
47  
      else
48  
        c = new JPanel;
49  
      addTabWithToolTip(tabs, name, toolTip, wrap(c));
50  
    }
51  
  }
52  
  if (idx != 0)
53  
    tabs.setSelectedIndex(min(tabs.getTabCount()-1, idx));
54  
  ret tabs;
55  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 10 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qsqiayxyrbia, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1020846
Snippet name: fillJTabs - fill JTabbedPane
Eternal ID of this version: #1020846/14
Text MD5: 8b000d634455409870fa1999a7722f12
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-31 22:52:47
Source code size: 1556 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 358 / 500
Version history: 13 change(s)
Referenced in: [show references]