Libraryless. Click here for Pure Java version (2953L/18K).
1 | sbool swingFontScale_debug; |
2 | |
3 | static void swingFontScale(double scale) { |
4 | swingFontScale((float) scale); |
5 | } |
6 | |
7 | static void swingFontScale(float scale) swing { |
8 | vm_generalMap_set('swingFontScale_value, scale); |
9 | Map<String, Font> swingFontScale_originals = cast vm_generalMap_get('swingFontScale_originals); |
10 | if (swingFontScale_originals == null) { |
11 | vm_generalMap_set('swingFontScale_originals, swingFontScale_originals = new HashMap); |
12 | for (Map.Entry entry : UIManager.getDefaults().entrySet()) { |
13 | O key = entry.getKey(); |
14 | if (key.toString().toLowerCase().contains(".font")) { |
15 | O value = entry.getValue(); |
16 | Font font = null; |
17 | if (swingFontScale_debug) |
18 | print("swingFontScale found value: " + key + " = " + value); |
19 | |
20 | if (value cast UIDefaults.LazyValue) |
21 | value = value.createValue(UIManager.getDefaults()); |
22 | else if (value cast UIDefaults.ActiveValue) |
23 | // ActiveValue is supposed to create the value every time but we ignore that. Hopefully this works anyway. |
24 | value = value.createValue(UIManager.getDefaults()); |
25 | |
26 | if (value cast Font) |
27 | swingFontScale_originals.put(key.toString(), value); |
28 | } |
29 | } |
30 | } |
31 | |
32 | for (S key, Font font : swingFontScale_originals) { |
33 | Font font2 = font.deriveFont(Font.PLAIN, font.getSize()*scale); |
34 | if (swingFontScale_debug) |
35 | print("swingFontScale " + scale + ": Setting " + key + " = " + font2); |
36 | UIManager.put(key, font2); |
37 | } |
38 | |
39 | //revalidateAllFrames(); |
40 | } |
41 | |
42 | static float swingFontScale() { |
43 | ret getSwingFontScale(); |
44 | } |
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
ID | Author/Program | Comment | Date |
---|---|---|---|
1326 | stefan | From https://stackoverflow.com/questions/34149453/java-swing-application-too-small-in-hidpi-computers?noredirect=1&lq=1 | 2017-08-24 00:48:51 |
Snippet ID: | #1009903 |
Snippet name: | swingFontScale - try to scale all fonts in UI - should recreate all windows+components after this (may weirdly break existing windows) |
Eternal ID of this version: | #1009903/16 |
Text MD5: | f5757d12aad315f9bc6185aca5ba5da5 |
Transpilation MD5: | 5cb01052fc71722f0f9082df32b0e78c |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-10 18:40:55 |
Source code size: | 1620 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 1071 / 1215 |
Version history: | 15 change(s) |
Referenced in: | [show references] |