Question

When you add a JToolBar to a component, you can drag it out and it create a new floating window while the parent component is also there. How can I make JToolBar show this floating window automatically with the parent invisible?

Was it helpful?

Solution

You can override javax.swing.plaf.basic.BasicToolBarUI and set its parent to the instance of a container (JDialog, JFrame). This should create a floating toolbar by default.

You can set the BasicToolbarUI like below:

ui = new BasicToolBarUI();
toolBar = new JToolBar();
toolBar.setUI(ui);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top