سؤال

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