static Rectangle restrictWindowToScreenSize_maxBounds = maxWindowBounds(); svoid restrictWindowToScreenSize(Window window) { if (window == null) ret; onBoundsChange(window, new Runnable { int recursionCounter; run { Rectangle max = restrictWindowToScreenSize_maxBounds; Rectangle r = window.getBounds(); if (r.width > max.width || r.height > max.height) { if (recursionCounter != 0) ret with warn("restrictWindowToScreenSize recursion"); ++recursionCounter; try { window.setSize(min(r.width, max.width), min(r.height, max.height)); } finally { --recursionCounter; } } } }); }