Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 431425

Summary: [GTK3] [GTK3.8] combo too small in vertical direction
Product: [Eclipse Project] Platform Reporter: Michelle Murray <mmurray>
Component: SWTAssignee: Snjezana Peco <snjezana.peco>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: adietish, akurtakov, arunkumar.thondapu, bfitzpat, ericwill, jonny.lamb, malaperle, manderse, snjezana.peco, wayne.beaton
Version: 4.4Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/47472
Whiteboard:
Bug Depends on:    
Bug Blocks: 437850    
Attachments:
Description Flags
Too short combo boxes
none
The second one has no content.
none
After resizing; the first one has no content none

Description Michelle Murray CLA 2014-03-27 23:40:07 EDT
Created attachment 241352 [details]
Too short combo boxes

Using Eclipse M6 and GTK3, combo boxes are too short in vertical direction when using GTK3 - see attached screen cap. But those same boxes are the correct size when using same version of Eclipse but with GTK2.
Comment 1 Alexander Kurtakov CLA 2014-03-28 11:37:16 EDT
Can you provide a pure swt reproducer for this code to test?
Comment 2 Andre Dietisheim CLA 2014-03-28 12:43:52 EDT
This should reproduce it (not tested):

public class Snippet {
	public static void main (String [] args) {
		Display display = new Display ();
		Shell shell = new Shell (display);
		shell.setSize (200, 200);
		Composite parent = new Composite(shell, SWT.NONE);
		GridLayoutFactory.fillDefaults().applyTo(parent);
		Combo combo = new Combo(parent, SWT.READ_ONLY);
		combo.setItems (new String [] {"Alpha", "Bravo", "Charlie"});
		GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(combo);
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}

My guess is that what's causing it is SWT.CENTER for the griddata that's applied to the combo. In GTK2 (which I'm running, I cant use GTK3) the combo has a preferred height that allows it to show the full item text. In GTK3 the item text is cropped (as shown in the screenshot.
Comment 3 Alexander Kurtakov CLA 2014-04-01 15:42:22 EDT
I tried the snippet but it doesn't show anything in the shell until I set some layout to it and after doing this the combo looks just fine.
Comment 4 Alexander Kurtakov CLA 2014-07-10 07:15:03 EDT
Michelle, Would you please test with final Luna release?
Comment 5 Max Rydahl Andersen CLA 2014-08-26 07:48:30 EDT
Just to let you know the issue is still present in final luna.

we will try get plain SWT sample.
Comment 6 Wayne Beaton CLA 2015-04-01 14:12:46 EDT
This problem exists in the Mars builds (I'm currently using M6). I see it manifest in a bunch of different places. AFAICT, it happens when the widget is created but not given content before opening.

If I provide content after opening and then resize the window, it makes everything right. When I emptied the combo--the one that had previously had content and was sized correctly--and resized; the emptied combo box resized too small.

I modified Snippet 26 to provide an example. I'll also post a screenshot.

/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package stuff;

/*
 * Combo example snippet: create a combo box (non-editable)
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet26 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setLayout(new GridLayout(1, true));
	
	Combo combo = new Combo (shell, SWT.READ_ONLY);
	GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
	combo.setLayoutData(data);
	combo.setItems (new String [] {"Alpha", "Bravo", "Charlie"});
	
	Combo combo2 = new Combo (shell, SWT.READ_ONLY);
	GridData data2 = new GridData(SWT.FILL, SWT.TOP, true, false);
	combo2.setLayoutData(data2);
		
	shell.setSize(300, 100);
	shell.open ();

	combo.setItems(new String[0]);
	combo2.setItems (new String [] {"Alpha", "Bravo", "Charlie"});
	
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}

}
Comment 7 Wayne Beaton CLA 2015-04-01 14:14:20 EDT
Created attachment 252091 [details]
The second one has no content.
Comment 8 Wayne Beaton CLA 2015-04-01 14:14:58 EDT
Created attachment 252092 [details]
After resizing; the first one has no content
Comment 9 Wayne Beaton CLA 2015-04-01 14:20:21 EDT
I'm not sure if this is related (perhaps it's the same or similar code), but I'm seeing the same thing with a text field. Except that it initially sizes short and--whether I add content to it or not--it changes to the expected dimensions when I resize the window.

	Text text = new Text(shell, SWT.BORDER);
	text.setLayoutData(data2);

For completeness, I tried adding a pack() statement. It did not fix the problem (though, as expected, resizing did).
Comment 10 Wayne Beaton CLA 2015-04-01 15:02:23 EDT
But wait... there's more. This only seems to be an issue when the style is SWT.READ_ONLY. Setting it to SWT.NONE results in a correctly-sized combo.
Comment 11 Wayne Beaton CLA 2015-04-01 16:04:36 EDT
So I did a little digging, and it seems that GTK really wants the widget to be sized the way it is.

I created a similar example in Python with the same result (except that the widget resized when I clicked it). 

I can't imagine that this is desired behaviour. Is this a GTK bug? Is it version specific?

gtk3-3.10.9-2.fc20.x86_64
Comment 12 Eclipse Genie CLA 2015-05-07 13:54:26 EDT
New Gerrit change created: https://git.eclipse.org/r/47472
Comment 13 Snjezana Peco CLA 2015-05-07 13:56:32 EDT
The issue described in comment #0 can't be reproduced anymore.
As to the issue described in comment #6, it happens because
GTK3 calculates the height of a combo that doesn't have any items differently from a combo that does them.
The patch fixes the issue by calling the Combo.getParent().layout() when the combo's items are changed. 

The patch https://git.eclipse.org/r/47472 also fixes bug 465023.
Comment 14 Snjezana Peco CLA 2015-05-07 13:58:59 EDT
*** Bug 465023 has been marked as a duplicate of this bug. ***
Comment 15 Alexander Kurtakov CLA 2015-08-28 11:24:11 EDT
(In reply to Snjezana Peco from comment #13)
> The issue described in comment #0 can't be reproduced anymore.
> As to the issue described in comment #6, it happens because
> GTK3 calculates the height of a combo that doesn't have any items
> differently from a combo that does them.
> The patch fixes the issue by calling the Combo.getParent().layout() when the
> combo's items are changed. 
> 
> The patch https://git.eclipse.org/r/47472 also fixes bug 465023.

Re layouting the parent can be quite expensive operation so another approach would be needed.
Comment 16 Snjezana Peco CLA 2015-08-30 14:51:21 EDT
(In reply to Alexander Kurtakov from comment #15)
> 
> Re layouting the parent can be quite expensive operation so another approach
> would be needed.

The operation is called only when combo's items have been changed which doesn't happen often.
I have refactored the patch so that the operation is called only when the number of items changes from 0 to 1+ items.
Comment 17 Arun Thondapu CLA 2015-10-23 17:22:43 EDT
I'm still not completely sure if this patch is the right fix for this bug, moving to M4 as it would need to be looked at more closely...
Comment 18 Arun Thondapu CLA 2016-05-04 06:04:59 EDT
Does this problem still exist in the latest Neon builds?

Also, if it still exists but is specific to GTK 3.8 and below and fixed in later versions of GTK, I wouldn't bother fixing it on our side anymore...
Comment 19 Snjezana Peco CLA 2016-05-05 10:56:17 EDT
(In reply to Arun Thondapu from comment #18)
> Does this problem still exist in the latest Neon builds?
> 
> Also, if it still exists but is specific to GTK 3.8 and below and fixed in
> later versions of GTK, I wouldn't bother fixing it on our side anymore...

The issue still exists on Neon and it is GTK 3.8 specific. See https://issues.jboss.org/browse/JBDS-3574
Comment 20 Eric Williams CLA 2018-04-09 17:12:35 EDT
(In reply to Snjezana Peco from comment #19)
> (In reply to Arun Thondapu from comment #18)
> > Does this problem still exist in the latest Neon builds?
> > 
> > Also, if it still exists but is specific to GTK 3.8 and below and fixed in
> > later versions of GTK, I wouldn't bother fixing it on our side anymore...
> 
> The issue still exists on Neon and it is GTK 3.8 specific. See
> https://issues.jboss.org/browse/JBDS-3574

Bugs specific to older GTK3 versions (especially something as old as 3.8) are no longer being fixed as the time investment is not worth it. GTK3.22 is the stable and final release of GTK3, and eventually all systems will ship with that version (most do already).