DragTabFrame closing inconsistently

妖精的绣舞 提交于 2019-12-01 05:50:29

Deactivating the timer, the inconsistencies I found were when dragging the last tab into a new (no existing) frame. That was because of a bad placed else that didn't let the code responsible for checking and closing the original Frame to run. I've modified it like this and it works so far, without the timer:

    @Override
    public void mouseReleased(MouseEvent e) {
        JComponent c = (JComponent) e.getSource();
        if (c.getTopLevelAncestor().getBounds().contains(e.getLocationOnScreen())) {
            // do nothing, the drop point is the same frame
        } else {
            DragTabFrame dtf = getTargetFrame(e.getLocationOnScreen());
            if (dtf == null) {
                dtf = new DragTabFrame();
                dtf.init();
                dtf.setLocation(e.getLocationOnScreen());
            }// else {
            DragTabFrame fromFrame = dragTabManager.getCurrentFrame();
            fromFrame.removeTabComponent(c);
            JTabbedPane tp = fromFrame.getTabbedPane();
            if (tp.getTabCount() == 0) {
                fromFrame.setVisible(false);
                fromFrame.dispose();
            } 
            //}
            dtf.addTabComponent(dragTabManager.getCurrentTitle(), c);
            dtf.pack();
            dtf.setVisible(true);
        }
    }

[...]

public DragTabManager() {
    /* unused actionlistener code here */

    //timer = new Timer(200,actionListener);
    //timer.start();
}

I don't think there should be any other problems, though I don't know about that closing JVM problem you mentioned.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!