Question

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

How to remove btnTask from JToolBar?

Thanx.

Was it helpful?

Solution

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.

OTHER TIPS

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().

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top