Search code examples
javaswingjtoolbar

how to remove item from jtoolbar


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

How to remove btnTask from JToolBar?

Thanx.


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.