Libraryless. Click here for Pure Java version (2953L/18K).
sbool swingFontScale_debug; static void swingFontScale(double scale) { swingFontScale((float) scale); } static void swingFontScale(float scale) swing { vm_generalMap_set('swingFontScale_value, scale); Map<String, Font> swingFontScale_originals = cast vm_generalMap_get('swingFontScale_originals); if (swingFontScale_originals == null) { vm_generalMap_set('swingFontScale_originals, swingFontScale_originals = new HashMap); for (Map.Entry entry : UIManager.getDefaults().entrySet()) { O key = entry.getKey(); if (key.toString().toLowerCase().contains(".font")) { O value = entry.getValue(); Font font = null; if (swingFontScale_debug) print("swingFontScale found value: " + key + " = " + value); if (value cast UIDefaults.LazyValue) value = value.createValue(UIManager.getDefaults()); else if (value cast UIDefaults.ActiveValue) // ActiveValue is supposed to create the value every time but we ignore that. Hopefully this works anyway. value = value.createValue(UIManager.getDefaults()); if (value cast Font) swingFontScale_originals.put(key.toString(), value); } } } for (S key, Font font : swingFontScale_originals) { Font font2 = font.deriveFont(Font.PLAIN, font.getSize()*scale); if (swingFontScale_debug) print("swingFontScale " + scale + ": Setting " + key + " = " + font2); UIManager.put(key, font2); } //revalidateAllFrames(); } static float swingFontScale() { ret getSwingFontScale(); }
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: | 1072 / 1215 |
Version history: | 15 change(s) |
Referenced in: | [show references] |