开发者

how to remove item from jtoolbar

开发者 https://www.devze.com 2022-12-24 16:38 出处:网络
private JButton btnTask = new JButton(); ... TaoGlobal.taskbar.add(btnTa开发者_如何学编程sk); How to remove btnTask 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

精彩评论

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