如何在jDesktopPane中停止拖动事件



我想阻止在桌面窗格中拖动jInternalForm。我尝试了以下步骤:防止JInternalFrame被移出JDesktopPane

但这对我不起作用。

下面是一个比较简单的自定义DesktopManager的例子,它使内部框架保持在桌面的边界内:

public class BoundsDesktopManager extends DefaultDesktopManager
{
    /*
    **  This is called anytime a frame is moved. 
    **  This implementation keeps the frame from leaving the desktop.
    */
    @Override
    public void dragFrame(JComponent component, int x, int y)
    {
        // Deal only with internal frames
        if (component instanceof JInternalFrame)
        {
            JInternalFrame frame = (JInternalFrame)component;
            JDesktopPane desktop = frame.getDesktopPane();
            Dimension d = desktop.getSize();
            // Too far left or right?
            if (x < 0)
            {
                x = 0; 
            }
            else if (x + frame.getWidth() > d.width)
            {
                x = d.width - frame.getWidth();
            }
            //  Too high or low?
            if (y < 0)
            {
                y = 0;
            }
            else if (y + frame.getHeight() > d.height)
            {
                y = d.height - frame.getHeight();
            }
        }
        // Pass along the (possibly cropped) values to the normal drag handler.
        super.dragFrame(component, x, y);
    }
}

相关内容

  • 没有找到相关文章

最新更新