import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*; import java.beans.*; public class DesktopMgr extends DefaultDesktopManager { protected static final String RESIZING = "RESIZING"; public void beginResizingFrame(JComponent f, int dir) { f.putClientProperty(RESIZING, Boolean.TRUE); } public void endResizingFrame(JComponent f) { f.putClientProperty(RESIZING, Boolean.FALSE); } public void setBoundsForFrame(JComponent f, int x, int y, int w, int h) { if(f instanceof JInternalFrame == false) { super.setBoundsForFrame(f, x,y,w,h); } else { JInternalFrame frame = (JInternalFrame)f; boolean resizing = false; Object r = frame.getClientProperty(RESIZING); if( r != null && r instanceof Boolean) { resizing = ((Boolean)r).booleanValue(); } JDesktopPane desk = frame.getDesktopPane(); Dimension d = desk.getSize(); if(x<0) { if (resizing) w += x; else x=0; } else { if(x+w>d.width) { if(resizing) w = d.width-x; else x = d.width-w; } } if(y<0) { if(resizing) h+=y; else y=0; } else { if(y+h>d.height) { if(resizing) h = d.height-y; else y=d.height-h; } } super.setBoundsForFrame(f,x,y,w,h); } } }