I want to create a JToolBar without adding it into any JFrame window. If I have to add it, then how can I make it such that the toolbar is created as a floating toolbar not a docking toolbar?

有帮助吗?

解决方案

you are going to need to override BasicToolBarUI and set the toolbars parent to an instance of JDialog which is bound to the current frame, that way you can float a toolbar by default and keep it on top of the frame.

其他提示

You can add it to some panel and then make it float immediately by calling setFloating on its BasicToolBarUI, no need to override classes:

JPanel someParentPanel = ...; // BorderLayout?
JToolBar toolBar = ...; // Your toolBar

// It is mandatory for the JToolBar to have a parent component before calling ui.setFloating
someParentPanel.add(toolBar, BorderLayout.WEST);

// Now, make it float
BasicToolBarUI ui = (BasicToolBarUI) toolBar.getUI();
ui.setFloating(true, new Point(0, 0)); // Pass any point where you want it to appear

You can also make it dock by using the same method, but passing false as first parameter.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top