Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 293870 - [Coolbar] Combo box added to a toolbar is displayed with incorrect height.
Summary: [Coolbar] Combo box added to a toolbar is displayed with incorrect height.
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Windows All
: P3 normal with 5 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-01 08:39 EST by Alex Ignácio da Silva CLA
Modified: 2020-08-03 15:00 EDT (History)
8 users (show)

See Also:


Attachments
Screenshot on Linux x86 (Ubuntu 8.04). (14.12 KB, image/png)
2009-11-01 08:44 EST, Alex Ignácio da Silva CLA
no flags Details
Sample RCP application. (6.98 KB, application/x-gzip)
2009-11-01 08:45 EST, Alex Ignácio da Silva CLA
no flags Details
Screenshot on Windows Vista. (23.31 KB, image/png)
2010-11-24 09:09 EST, Alex Ignácio da Silva CLA
no flags Details
Screenshot on Windows 7. (40.07 KB, image/png)
2010-11-24 09:12 EST, Alex Ignácio da Silva CLA
no flags Details
Sample RCP project demonstrating a workaround to this bug. (12.75 KB, application/zip)
2010-11-24 14:30 EST, Alex Ignácio da Silva CLA
no flags Details
Combo cutoff on Win7, Eclipse 4.2.2 (20.47 KB, image/png)
2013-08-20 13:28 EDT, Chauncey Xu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Ignácio da Silva CLA 2009-11-01 08:39:32 EST
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.15) Gecko/2009102814 Ubuntu/8.04 (hardy) Firefox/3.0.15
Build Identifier: 20090920-1017

A combo box contributed to a toolbar (either the main application toolbar or a view's toolbar) is displayed with incorrect height on Linux x86 (see attached screenshot). This problem does not occur on Linux x86_64 or Windows XP.

The sample RCP application attached shows the problem and two possible workarounds to correct it:

1. Explicitly set the parent's size in the WorkbenchWindowControlContribution:

	@Override
	protected Control createControl(Composite parent) {
		Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
		combo.add("Option 1");
		combo.add("Option 2");
		combo.add("Option 3");
		combo.select(0);
		
		// this workaround fixes the problem
//		parent.setSize(combo.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		return combo;
	}

2. Add a command to the toolbar:

      <menuContribution
            locationURI="toolbar:org.eclipse.ui.main.toolbar">
         <toolbar
               id="test.toolbar1">
            <!-- adding a command fixes the problem -->
            <!--command
                  commandId="test.command1"
                  icon="icons/alt_window_16.gif"
                  style="push">
            </command-->
            <control
                  class="test.NullControlContribution">
            </control>
         </toolbar>
      </menuContribution>


Reproducible: Always

Steps to Reproduce:
1. Run the attached sample application.
2. Verify that the combo boxes contributed to the toolbars are displayed with incorrect height on Linux x86.
3. Uncomment the workarounds to verify that they fix the problem.
Comment 1 Alex Ignácio da Silva CLA 2009-11-01 08:44:36 EST
Created attachment 151022 [details]
Screenshot on Linux x86 (Ubuntu 8.04).

Screenshot showing the problem on Linux x86 (Ubuntu 8.04).
Comment 2 Alex Ignácio da Silva CLA 2009-11-01 08:45:32 EST
Created attachment 151023 [details]
Sample RCP application.

Sample RCP application showing the problem and possible workarounds to fix it.
Comment 3 Alex Ignácio da Silva CLA 2009-11-01 08:48:00 EST
Maybe this could be related to bug 183003, or even a duplicate of it.

I'm not sure as I don't know how the RCP contributions are translated into the basic SWT building blocks.
Comment 4 Alex Ignácio da Silva CLA 2010-11-24 09:09:34 EST
Created attachment 183754 [details]
Screenshot on Windows Vista.
Comment 5 Alex Ignácio da Silva CLA 2010-11-24 09:12:18 EST
Created attachment 183755 [details]
Screenshot on Windows 7.
Comment 6 Alex Ignácio da Silva CLA 2010-11-24 09:15:53 EST
Actually the problem occurs in Windows Vista and Windows 7 as well (see screenshots above), where the proposed workaround of setting

parent.setSize(combo.computeSize(SWT.DEFAULT, SWT.DEFAULT));

does not work.
Comment 7 Alex Ignácio da Silva CLA 2010-11-24 14:30:55 EST
Created attachment 183792 [details]
Sample RCP project demonstrating a workaround to this bug.
Comment 8 Alex Ignácio da Silva CLA 2010-11-24 14:41:49 EST
Based on the hack provided in bug 183003 comment 24, I've developed a new workaround that will work on Windows (this is evidence that this is indeed a duplicate of that bug). Unfortunately it doesn't work on Linux, but in that platform we can still resort to the first workaround of setting:

parent.setSize(combo.computeSize(SWT.DEFAULT, SWT.DEFAULT));

I've attached another sample RCP project illustrating the complete workaround that will work in both platforms. It's getting too complex, and I'm not confident that it won't get broken by the next OS version of even Eclipse platform update... It would be great if that bug could start receiving some attention again.

Below is a sample of the workaround for adding combo boxes in a view's toolbar. The workaround for a combo in the main application's toolbar is a slightly more complex; please have a look at the attached RCP project for details.

    @Override
    protected Control createControl(Composite parent) {
        final Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
        combo.add("Option 1");
        combo.add("Option 2");
        combo.add("Option 3");
        combo.select(0);

        // The applied workaround varies according to the platform.
        // Only the selected workaround will work for a given platform.
        if(SWT.getPlatform().equals("win32")) {
            parent.getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    getParent().add(new ContributionItem() {

                        private ToolItem dummyItem;

                        @Override
                        public void fill(ToolBar parent, int index) {
                            if(dummyItem == null) {
                                dummyItem = new ToolItem(parent, SWT.PUSH, index);

                                final Image image = new Image(parent.getDisplay(), 1,
                                        combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
                                GC gc = new GC(image);
                                gc.setBackground(parent.getBackground());
                                gc.fillRectangle(image.getBounds());
                                gc.dispose();

                                dummyItem.setImage(image);
                                dummyItem.addDisposeListener(new DisposeListener() {
                                    @Override
                                    public void widgetDisposed(DisposeEvent e) {
                                        image.dispose();
                                    }
                                });

                                setVisible(false);
                                getParent().update(true);
                            }
                        }
                    });

                    getParent().update(true);
                }
            });
        } else {
            parent.setSize(combo.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }

        return combo;
    }
Comment 9 Chauncey Xu CLA 2013-08-20 13:25:36 EDT
The workaround above for Win32 does not work for me. Still seeing the combobox cutoff from below. Attaching screen shot.
Comment 10 Chauncey Xu CLA 2013-08-20 13:28:17 EDT
Created attachment 234584 [details]
Combo cutoff on Win7, Eclipse 4.2.2
Comment 11 Benoit Lagree CLA 2013-09-17 03:26:18 EDT
A working workaround (at least on Windows 7) is to use the Nebula TableCombo widget
Comment 12 Henno Vermeulen CLA 2014-02-06 04:05:23 EST
I see a similar issue with buttons placed in a Composite with a grid layout with no margins. A single button displays OK and has computed height 25. The Composite also has a computed height of 25 but the buttons somehow grow larger and are clipped.
Comment 13 Eclipse Genie CLA 2020-08-03 15:00:25 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.