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

29
LINES

< > BotCompany Repo | #1001438 // fillTableWithStrings

JavaX fragment (include)

static void fillTableWithStrings(final JTable table, L<L<S>> rows, L<S> colNames) {
  fillTableWithStrings(table, rows, toStringArray(colNames));
}

// thread-safe
static void fillTableWithStrings(final JTable table, L<L<S>> rows, S... colNames) {
  final DefaultTableModel model = fillTableWithStrings_makeModel(rows, colNames);
  
  awtIfNecessary {
    setTableModel(table, model);
  }
}

static DefaultTableModel fillTableWithStrings_makeModel(L<L<S>> rows, S... colNames) {
  Object[][] data = new Object[rows.size()][];
  int w = 0;
  for (int i = 0; i < rows.size(); i++) {
    L<S> l = rows.get(i);
    Object[] r = new Object[l.size()];
    for (int j = 0; j < l.size(); j++)
      r[j] = l.get(j);
    data[i] = r;
    w = Math.max(w, l.size());
  }
  O[] columnNames = new O[w];
  for (int i = 0; i < w; i++)
    columnNames[i] = i < l(colNames) ? colNames[i] : "?";
  ret new DefaultTableModel(data, columnNames);
}

Author comment

Began life as a copy of #1001431

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: #1001438
Snippet name: fillTableWithStrings
Eternal ID of this version: #1001438/1
Text MD5: 01711fb2ac828e8a0eab5c01a9df8a60
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-29 18:19:15
Source code size: 957 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 780 / 1173
Referenced in: [show references]