DragTabFrame closing inconsistently

后端 未结 1 400
离开以前
离开以前 2021-01-13 09:20

The code below is supposed to work a little like the Multi-Document Interface (MDI) you might see in a browser like FF, IE or Chrome. It presents \'documents\' (a black bu

相关标签:
1条回答
  • 2021-01-13 09:42

    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.

    0 讨论(0)
提交回复
热议问题