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

26
LINES

< > BotCompany Repo | #1001537 // setTableModel - tries to preserve selection & column widths

JavaX fragment (include)

1  
static Map<JTable, VF1<JTable>> setTableModel_after = weakHashMap();
2  
static Map<JTable, VF2<JTable, RowSorter>> setTableModel_fixSorter = weakHashMap();
3  
4  
static void setTableModel(final JTable table, final TableModel model) {
5  
  swing {
6  
    Map<S, Int> widths = tableColumnWidthsByName(table);
7  
    int[] i = table.getSelectedRows();
8  
    TableRowSorter sorter = model.getColumnCount() == tableColumnCount(table) ? (TableRowSorter) table.getRowSorter() : null;
9  
    L<? extends RowSorter.SortKey> sortKeys = sorter == null ? null : sorter.getSortKeys();
10  
    table.setModel(model);
11  
    int n = model.getRowCount();
12  
    ListSelectionModel sel = table.getSelectionModel();
13  
    for (int j = 0; j < i.length; j++)
14  
      if (i[j] < n)
15  
        sel.addSelectionInterval(i[j], i[j]);
16  
    tableSetColumnPreferredWidths(table, widths);
17  
    if (sorter != null) {
18  
      sorter.setModel(model);
19  
      callF(setTableModel_fixSorter.get(table), table, sorter);
20  
      //print("Keeping sorter: " + sorter + " Sort keys: " + sortKeys);
21  
      if (sortKeys != null) sorter.setSortKeys(sortKeys);
22  
    }
23  
    table.setRowSorter(sorter);
24  
    callF(setTableModel_after.get(table), table);
25  
  }
26  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001537
Snippet name: setTableModel - tries to preserve selection & column widths
Eternal ID of this version: #1001537/22
Text MD5: b95f2e417a7e7ab38e85985887446523
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-07 01:29:38
Source code size: 1191 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 821 / 1265
Version history: 21 change(s)
Referenced in: [show references]