Project: Eclipse_Platform_UI
Bug 123205 [Contributions] ToolBarManger displays wrong number of items, if pack() is not called
Reported: 2006-01-10 02:56:38 | Status: verified fixed

I have added bunch of Action items into the ToolBarManager. After each addition, I call an update, which is kind of required for the design, I currently have. Here are my observations: 1. If I do not call pack(), only one button shows up. 2. If I only use the LAST update, then all button shows up, no matter, whether I use size(), pack(), or leave both those out. Please find below the SWT code snippet to reproduce the problem. I am using 3.2M3 Build Id: I20051102-1600 <code> import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; public class SampleUI { public static void main( String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout( new GridLayout(1, false)); //Create Images Image blueImage = new Image ( Display.getCurrent(), 20, 20); Color color = Display.getCurrent().getSystemColor (SWT.COLOR_BLUE); GC gc = new GC ( blueImage); gc.setBackground (color); gc.fillRectangle ( blueImage.getBounds ()); gc.dispose(); Image greenImage = new Image ( Display.getCurrent(), 20, 20); color = Display.getCurrent().getSystemColor (SWT.COLOR_GREEN); gc = new GC ( greenImage); gc.setBackground (color); gc.fillRectangle ( greenImage.getBounds ()); gc.dispose(); Image redImage = new Image ( Display.getCurrent(), 20, 20); color = Display.getCurrent().getSystemColor (SWT.COLOR_RED); gc = new GC ( redImage); gc.setBackground (color); gc.fillRectangle ( redImage.getBounds ()); gc.dispose(); ToolBarManager toolBarManager = new ToolBarManager( new ToolBar( shell, SWT.FLAT)); toolBarManager.add( new TestAction( blueImage)); toolBarManager.update( true); toolBarManager.add( new TestAction( greenImage)); toolBarManager.update( true); toolBarManager.add( new TestAction( redImage)); toolBarManager.update( true); //Only leaving this one, eliminates the problem shell.setSize( 200, 200); //Setting the SIZE shows only 1 button //shell.pack(); //Calling PACK, shows all buttons shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } class TestAction extends Action { public TestAction( Image image) { setImageDescriptor( ImageDescriptor.createFromImage( image)); } public void run() { System.out.println( "Key Pressed"); } } </code>

Files changed in fix:
bundles/org.eclipse.jface/src/org/eclipse/jface/action/ToolBarManager.java