Libraryless. Click here for Pure Java version (20447L/126K).
sclass TableSearcher { JTable table; JTextField tfInput; JComponent searchPanel, panel; F2<S, Map, Bool> rowTester; L<Int> rowIndices; SingleComponentPanel scpRightOfSearchPanel = scp(); L lastFiltered, lastOriginal; S input() { ret gtt(tfInput); } void clearSearchField { setText(tfInput, ""); } } static TableSearcher tableWithSearcher2(JTable t, O... _) { new TableSearcher s; bool precise = true; s.table = t; s.tfInput = jtextfield(); s.rowTester = func(S pat, Map row) -> bool { anyValueContainsIgnoreCase(row, pat) }; onUpdate(s.tfInput, new Runnable { public void run() { S pat = s.input(); L<Map<S, O>> data = rawTableData(t); if (eq(s.lastFiltered, data)) data = s.lastOriginal; //print("Searching " + n(l(data), "entry")); new L data2; new L<Int> rowIndices; for i over data: { Map<S, O> map = data.get(i); if (isTrue(callF(s.rowTester, pat, map))) { data2.add(map); rowIndices.add(i); } } //print("Found " + n(l(data2), "entry")); s.lastFiltered = data2; s.lastOriginal = data; dataToTable(t, data2); if (precise) s.lastFiltered = rawTableData(t); s.rowIndices = rowIndices; } }); s.searchPanel = centerAndEast(withLabel(" Search:", s.tfInput), s.scpRightOfSearchPanel); JComponent top = s.searchPanel; s.panel = boolOptPar(_, 'withMargin) ? northAndCenterWithMargin(top, t) : northAndCenter(top, t); ret s; }
Began life as a copy of #1004385
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, elmgxqgtpvxh, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016898 |
Snippet name: | tableWithSearcher2 - add search bar on top of JTable, return a class |
Eternal ID of this version: | #1016898/15 |
Text MD5: | 1338a68f0b1e3bc5fc2b6c5cb0ad2d58 |
Transpilation MD5: | c28141429f42c5b430d65e524df9336a |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-30 13:00:02 |
Source code size: | 1596 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 508 / 633 |
Version history: | 14 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1027829 - tableWithSearcher2_returnPanel |