Search code examples
javaswingborder-layoutjtoolbar

Is there a way to find which region BorderLayout has docked a user draggable JToolBar


I have user draggable JToolBars added to the NORTH, EAST and WEST regions of a JPanel with a BorderLayout. When the app exits I would like to save the region that the user has docked the JToolBars to, in order to respect this preference on next app launch.

I've examined the property change listener approach, and tried obtaining the instance of BorderLayout on the JPanel and inquiring as to the Constraints each added component has, but am unable to find the right info. I've trawled the source code too, and most of the user dragging appears to be delegated to the UI in effect and am struggling to keep context as I read through it all.

Any Swing aficionados know the answer here please?


Solution

  • Can't you just use ContainerListener

    public void componentAdded(ContainerEvent e);
    

    for your container to get the docking event?