0

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
LanguagesNamedAfterCofee
  • 5,782
  • 7
  • 45
  • 72
  • This doesn't make sense. A toolbar generally has components that perform actions pertaining to whatever is inside the parent frame, so disposing of the frame while keeping the toolbar visible seems a bit silly. Or have I misunderstood your question? – fireshadow52 Jun 28 '12 at 02:39
  • No, you've understood it correctly. There is another window which is what the components on the toolbar act upon, but I am not allowed to add components to it. This is why I want the self-floating toolbar. – LanguagesNamedAfterCofee Jun 28 '12 at 02:42

1 Answers1

2

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);
18bytes
  • 5,951
  • 7
  • 42
  • 69