JDesktopPane desktop = getDesktopPane(frame);
LayoutManager2 layoutManager = (LayoutManager2)desktop.getLayout();
Component componentToDock = desktop.getComponentAt(newX, newY);
if (componentToDock != null && componentToDock != frame) {
layoutManager.addLayoutComponent(frame, new DockConstraints(componentToDock, getDockLocation(componentToDock, newX, newY)));
layoutManager.layoutContainer(desktop);
}
if (frame instanceof JInternalFrame) {
setSelected((JInternalFrame)frame);
}
}