Turning off a floating JToolBar

I am developing an app that has several tabs in a JTabbedPane.  When a tab is selected I want a tab specific toolbar to be added to a panel 'toolPanel'  and then removed when the tab is deselected.

I have implemented a tablistener that adds and removes the toolbars and this works fine unless the user has dragged the toolbar off the toolPanel.  In that case the toolbar is still removed but the title of its JToolBar window is still there and can only be got rid of by clicking the close-window control.  I can make the toolbar not floatable but I dont want to.

This code is run when a tab is activated
    toolPanel.add(toolBar1);
    toolBar1.setVisible(true);

this code is run when the tab is deactivated
    toolPanel.remove(toolBar1);
    toolBar1.setVisible(false);
    toolPanel.paintAll(toolPanel.getGraphics());

Is there a better way of doing this and how do I get rid of the floating toolbars frame ?

I am using JSE6.

luckybonanzaAsked:
Who is Participating?
 
Siva Prasanna KumarConnect With a Mentor Principal Solutions ArchitectCommented:
If the toolbar is tab specific i think its better to disable the floating of the toolbar

      toolbar .setFloatable(false) ;
0
 
objectsCommented:
try:

toolPanel.revalidate();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.