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

44
LINES

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

JavaX fragment (include)

// x = names and components interleaving.
// or just components.
// or just names.
// also, first element can be index of tab to open at start
// also, SUPER short demo syntax: jtabs(3)
// also, you can pass a Collection containing the elements
static JTabbedPane fillJTabs(final JTabbedPane tabs, fO... _x) {
  if (tabs == null) null;
  clearTabs(tabs);
  O[] x = flattenArray2(_x);
  ifdef fillJTabs_debug
  print("fillJTabs length=" + l(_x) + " => " + l(x));
  endifdef
  int idx = 0;
  if (get(x, 0) instanceof Int) {
    idx = asInt(get(x, 0));
    x = dropFirst(x);
    if (empty(x)) {
      x = arrayrep(null, idx);
      idx = 0;
    }
  }
  int n = 0;
  for (int i = 0; i < l(x); i++) {
    ++n;
    if (isComponentOrSwingable(x[i]))
      addTab(tabs, "Tab " + n, wrap(x[i]);
    else {
      S name = str(or(x[i], "Tab " + n));
      ifdef fillJTabs_debug
      print("tab " + i + ": " + name);
      endifdef
      Component c;
      if (isComponentOrSwingable(get(x, i+1)))
        c = wrap(get(x, ++i));
      else
        c = new JPanel;
      addTab(tabs, name, wrap(c));
    }
  }
  if (idx != 0)
    tabs.setSelectedIndex(min(tabs.getTabCount()-1, idx));
  ret tabs;
}

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1020846
Snippet name: fillJTabs - fill JTabbedPane
Eternal ID of this version: #1020846/10
Text MD5: 50a5d9710f0fd2b7b98dc1fde6d84d2d
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-09 10:23:48
Source code size: 1229 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 142 / 212
Version history: 9 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1020846 & http://1020846.tinybrain.de