views:

71

answers:

3

private JButton btnTask = new JButton(); ... TaoGlobal.taskbar.add(btnTask);

How to remove btnTask from JToolBar?

Thanx.

+2  A: 

JToolBar is a Container, and hence removal can be achieved via toolbar.remove(btnTask).

If you look at that javadoc you'll see other useful methods, like remove(index) and removeAll().

Bozho
thanx, i tried remove, but forgotten for repaint: TaoGlobal.taskbar.remove(btnTask); TaoGlobal.taskbar.repaint();
rodion
+2  A: 

Maybe this would be useful for you: http://java.sun.com/docs/books/tutorial/uiswing/components/toolbar.html and http://java.sun.com/j2se/6/docs/api/javax/swing/JToolBar.html

The last link shows you all the methods that you can use.

juFo
try to avoid giving links to docs of 1.4.2
Bozho
woeps, sorry :$
juFo
@juFo: you're allowed to edit your answers.
trashgod
+2  A: 

i tried remove, but forgotten for repaint

Well the general code should be:

panel.remove(...);
panel.revalidate();
panel.repaint();

The revalidate() is important because it tells the panel to layout the components. Your code may work if your are removing the last component, but I doubt is will work when you remove the first component.

camickr