开发者

how to remove item from jtoolbar

private JButton btnTask = new JButton(); ... TaoGlobal.taskbar.add(btnTa开发者_如何学编程sk);

How to remove btnTask from JToolBar?

Thanx.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜