How can I make a floating JToolBar that is always on top?

Sandip Chitale

If you are talking about the standard floating behaviour of JToolBar in Swing, you are out of luck. The reason is that the standard implementation adds the floating JToolBar to a JFrame. That is the reason why the floating JToolBar can go behind the Main Applications frame from where it was floated. That is because Frames are treated as siblings by the Windowing System and can overlap each other.

If you want to manage floating yourself you could turn of the default floating by calling toolBar.setFloatable(false);. Then add a MouseMotionListener to the JToolBar. React to mouseDrag events. When the drag event followed by a mouse released has it's coordinates outside the area of the JToolBar you could remove it from the frame and add it to a non-resizable, non-modal dialog whose parent is the original application frame. When you show the dialog call pack() on it. The non-modality allows interaction with the main application Frame. The dialog by it's nature floats on the top of the main application Frame. For docking you could do the same thing in reverse way.