removeDockable does not work on nested dockables

Hi,

station.removeDockable does not work if the dockable is nested inside another.
frontend.removeDockable has the same problem.
The code below demonstrates this problem, when you run it, you’ll notice the „b“ panel still shows despite being removed. (tested in version 1.1.1)

Regards,
the Docktor :slight_smile:



import java.awt.BorderLayout;
import java.awt.Frame;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import bibliothek.gui.DockController;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.DefaultDockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.station.split.DockableSplitDockTree;
import bibliothek.gui.dock.station.split.SplitDockTree;


public class DockRemoveProblem extends JFrame {

    public DockRemoveProblem() {

        // init
        DockController controller = new DockController();
        controller.setRootWindow(this);
        SplitDockStation station = new SplitDockStation();
        controller.add(station);

        // create dockables
        DefaultDockable da = new DefaultDockable(new JPanel(),"a");
        DefaultDockable db = new DefaultDockable(new JPanel(),"b");
        DefaultDockable dc = new DefaultDockable(new JLabel("c"),"c");
        DefaultDockable dd = new DefaultDockable(new JLabel("d"),"d");
        
        // set structure
        DockableSplitDockTree tree = new DockableSplitDockTree();
        SplitDockTree<Dockable>.Key group = tree.put(new Dockable[]{ da, db});
        SplitDockTree<Dockable>.Key topTree = tree.horizontal( dc, dd, 1.0/4.0 );
        SplitDockTree<Dockable>.Key root = tree.vertical( topTree, group, 0.5 );
        tree.root(root);
        station.dropTree(tree);

        // remove db / dd
        station.removeDockable(db); // this one is not removed!!!
        station.removeDockable(dd);
        

        setLayout(new BorderLayout());
        add(station, BorderLayout.CENTER);
    }
    
    
    public static void main(String... args) {

        SwingUtilities.invokeLater(new Runnable(){
            @Override
            public void run(){

                DockRemoveProblem appFrame = new DockRemoveProblem();
                appFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
                appFrame.setVisible(true);
            }
        });
    }
}


This was me. Forgot to log in.

You are searching for DockFrontend.hide, which makes a Dockable invisible. DockFrontend.remove releases a Dockable from the management system of the DockFrontend, this just means its location is no longer tracked.

By grouping “da” and “db”, a new DockStation is created and put between “station” and “da”/“db”. So “db” is not really a child of “station”, but a “grand child”. Just ask “db” for its real parent using “db.getDockParent”.

In any case: if you would use the Common API you would be using a CDockable, which offers the nice method “setVisible” - which is much more easy to use.

Hi Beni,

Thanks for the quick reply. If I do both:

  • frontend.hide
  • frontend.remove
    That works fine.

I create a lot of dockables then remove them again dynamically.
Will that call sequence remove the dockable and its memory use etc completely?

It should remove all traces. If it does not it would be a memory leak and a bug.

Great. Thanks again for the help.

(off-topic, english speaking people may find it hard to register/post because the questions to test for a human are written in German!)

You can change the language, at the bottom left corner there is a drop-down-box :wink: