static int fixInternalFrame_borderTopLeft = 0; static int fixInternalFrame_borderBottomRight = 40; static JInternalFrame fixInternalFrame(JInternalFrame f) { Container c = f.getParent(); if (c == null) ret f; Rect r = toRect(f.getBounds()); int a = fixInternalFrame_borderTopLeft, b = fixInternalFrame_borderBottomRight; Rect outer = new Rect(a, a, c.getWidth()-b, c.getHeight()-b); if (!rectsIntersect(r, outer)) f.setLocation( max(b, min(r.x, outer.x2())), max(b, min(r.y, outer.y2()))); ret f; }