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

53
LINES

< > BotCompany Repo | #1001611 // Swing: Show arbitrary Java list as table

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

Libraryless. Click here for Pure Java version (1534L/10K/34K).

1  
!747
2  
!actionListener {
3  
!awt {
4  
!pcall
5  
6  
m {
7  
  static JTable tbl;
8  
  static new L data;
9  
  
10  
  p {
11  
    data = (L) unstructure(loadSnippet("#1001610"), true);
12  
    
13  
    JFrame frame = new JFrame("A Table");
14  
    frame.setBounds(10, 10, 400, 400);
15  
16  
    tbl = new JTable();
17  
    updateTable();
18  
    
19  
    frame.getContentPane().add(new JScrollPane(tbl));
20  
    frame.setVisible(true);
21  
  }
22  
  
23  
  static void updateTable() {
24  
    new L<L<S>> rows;
25  
    new L<S> cols;
26  
27  
    if (data != null)    
28  
      for (O x : data) pcall {
29  
        if (x instanceof DynamicObject) {
30  
          DynamicObject dO = cast x;
31  
          new L<S> row;
32  
          for (S field : dO.fieldValues.keySet()) {
33  
            O value = dO.fieldValues.get(field);
34  
            int col = cols.indexOf(field);
35  
            if (col < 0) {
36  
              cols.add(field);
37  
              col = cols.size()-1;
38  
            }
39  
            dynSet(row, col, value instanceof S ? (S) value : structure(value));
40  
          }
41  
          rows.add(row);
42  
        } else
43  
          rows.add(litlist("?"));
44  
      }
45  
46  
    fillTableWithStrings(tbl, rows, cols);
47  
  }
48  
  
49  
  static void dynSet(L<S> l, int i, S s) {
50  
    while (i >= l.size()) l.add("");
51  
    l.set(i, s);
52  
  }
53  
}

Author comment

Began life as a copy of #1001437

Seems to work.

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1154 stefan See #1001612 2015-10-28 18:13:38

add comment

Snippet ID: #1001611
Snippet name: Swing: Show arbitrary Java list as table
Eternal ID of this version: #1001611/1
Text MD5: 14fed563b57a175081ec6a79fcc2689e
Transpilation MD5: 3ab2dad07aa15f911976ffac9625d535
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-28 18:13:44
Source code size: 1239 bytes / 53 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 741 / 764
Referenced in: [show references]