你的JInternalFrame移动起来很慢么?我也用的JDesktopPane和JinternalFrame做的多文档窗口,移动速度很快呀。而且资源的消耗也不是很大。

解决方案 »

  1.   

    我在JInternalFrame里用Graphics绘制了一些图形,如果只是单纯的移动几个位置,也没什么影响,但是如果托着来回绕,那CPU马上就到百分白了。很郁闷。所以想看看可不可以不让它重画里面的内容,最好的办法就是能够像JFrame那样只预先移动一个边框。等位置确定了在重画。
      

  2.   

    我觉得这个不是JInternalFrame的问题,你就是拖动一个资源管理器在屏幕上晃来晃去,CPU也会很高的。而且别人用程序估计也不会那样晃着看的。你看看代码中能不能减少重画的地方,如果不能减少,就这样吧。
      

  3.   

    在新的
    JDesktopPane desktopPane = new JDesktopPane()
    desktopPane.setDesktopManager(new OutlineManager());即可!class OutlineManager extends DefaultDesktopManager
    {
    private Rectangle start, last;
    private boolean first = true; // dragging...
    public void beginDraggingFrame(JComponent frame)
    {
    initializeOutline(frame);
    } public void dragFrame(JComponent frame, int x, int y)
    {
    updateOutline(frame, x, y, start.width, start.height);
    } public void endDraggingFrame(JComponent frame)
    {
    endOutline(frame);
    } // resizing...
    public void beginResizingFrame(JComponent frame, int dir)
    {
    initializeOutline(frame);
    } public void resizeFrame(JComponent frame, int x, int y, int w, int h)
    {
    updateOutline(frame, x, y, w, h);
    } public void endResizingFrame(JComponent frame)
    {
    endOutline(frame);
    } // outline...
    private void initializeOutline(final JComponent frame)
    {
    frame.setVisible(false);
    start = frame.getBounds();
    last = new Rectangle(start);
    first = true; SwingUtilities.invokeLater(new Runnable()
    {
    public void run()
    {
                 updateOutline(frame, start.x,  start.y, start.width, start.height);
    }
    });
    } public void updateOutline(JComponent frame, int x, int y, int w, int h)
    {
    Container _container = frame.getParent();
    Graphics g = _container.getGraphics(); try
    {
    g.setXORMode(_container.getBackground());
    if (!first)
    {
    g.drawRect(last.x,  last.y,  last.width-1, last.height-1);
    }
    g.drawRect(x, y, w-1, h-1);
    first = false;
    }
    finally
    {
    g.dispose();
    last.setBounds(x, y, w, h);
    }
    } public void endOutline(JComponent frame)
    {
    frame.setVisible(true);
    setBoundsForFrame(
    frame, last.x, last.y, last.width, last.height);
    }
    }