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

Bug 314815

Summary: Checkbox with null text will display a empty rectangle
Product: [Eclipse Project] Platform Reporter: DartPeng <blackfrezee>
Component: SWTAssignee: Alexander Kurtakov <akurtakov>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akurtakov, astevenson, cgold, Christoph.Krueger, mark, remy.suen, vrubezhny, vyemialyanchyk
Version: 3.5.2   
Target Milestone: 4.4 M6   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
unwanted widget
none
Mac screenshot ...
none
Screenshot from Linux using Chris's sample code
none
Screen shot from sample code I just posted (Linux)
none
The image of fixed checkbox with empty label
none
Luna, GTK3 and the Checkbox with empty label bug none

Description DartPeng CLA 2010-05-28 04:29:38 EDT
Build Identifier: M20090917-0800

I want to create a checkbox control and its text is on the left , but the it seems the checkbox doesn't support this feature , so I need to create a Label control on the left side of this checkbox , but the issue is the checkbox control will display a empty rectangle(I guess it's a empty text label control) on the right. 

Reproducible: Always

Steps to Reproduce:
1.create a label control with FormToolkit
2.create a checkbox control with FormToolkit
3.they are in a same container which has GridLayout
4.keep the checkbox's text is empty
Comment 1 Prakash Rangaraj CLA 2010-05-28 04:31:34 EDT
Can you attach a sample code?
Comment 2 DartPeng CLA 2010-05-28 04:31:49 EDT
Created attachment 170308 [details]
unwanted widget
Comment 3 DartPeng CLA 2010-05-28 04:34:55 EDT
(In reply to comment #1)
> Can you attach a sample code?

oh , you are so quickly.
The codes is very simple , just create two controls in the same parent container:

toolkit.createLabel(parent, "Label :")				.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));

gd = new GridData(SWT.FILL, SWT.NONE, true, false);

checkbox = toolkit.createButton(parent, null, SWT.CHECK); 
checkbox.setLayoutData(gd);
Comment 4 Prakash Rangaraj CLA 2010-05-28 04:54:39 EDT
> oh , you are so quickly.

   You haven't seen Remy in action. He can mark a bug as duplicate before even its submitted :-)

> The codes is very simple , just create two controls in the same parent
> container:
> 
> toolkit.createLabel(parent, "Label :")               
> .setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
> 
> gd = new GridData(SWT.FILL, SWT.NONE, true, false);
> 
> checkbox = toolkit.createButton(parent, null, SWT.CHECK); 
> checkbox.setLayoutData(gd);

    I can't reproduce this on 3.5.2 Could be a linux specific bug. Assigning to UA for investigation.
Comment 5 Prakash Rangaraj CLA 2010-05-28 04:55:30 EDT
Created attachment 170319 [details]
Mac screenshot ...

Same code tried in Mac
Comment 6 Chris Goldthorpe CLA 2010-05-28 14:20:26 EDT
Created attachment 170400 [details]
Screenshot from Linux using Chris's sample code

I tried this on Linux, the snippet did not give all the context so I extrapolated it a bit by creating a plug-in with a view from the the project wizard and replacing createPartControl with the code below. This tests with and without the FormToolkit. In either case I can see that a label is created for the checkbox, it does not have a border so it does not show until you select the checkbox at which time the label gets a selection box.

I'm not seeing the same type of control that you are, I was on RHEL5, it looks as though you are on Ububtu. In any case I think that what you are trying to do is not going to work for a number of reasons. Tabbing is not going to work correctly becuse the label attached to the checkbox is empty, this will not work for users with screenreaders.

	public void createPartControl(Composite parent) {
		Composite inner = new Composite(parent, SWT.NULL);
		inner.setLayout(new GridLayout(2, false));
		Button checkbox1, checkbox2;
		Label label1 = new Label(inner, SWT.NULL);
        checkbox1 = new Button(inner, SWT.CHECK);
		label1.setText("Label1 :");
		GridData gd1 = new GridData(SWT.FILL, SWT.TOP, true, false);
		checkbox1.setLayoutData(gd1);
		
		FormToolkit toolkit = new FormToolkit(parent.getDisplay());
		GridData gd2 = new GridData(SWT.FILL, SWT.TOP, true, false);
		toolkit.createLabel(inner, "Label2 :").setForeground(toolkit.getColors().getColor(IFormColors.TITLE));  
		checkbox2 = toolkit.createButton(inner, null, SWT.CHECK); 
		checkbox2.setLayoutData(gd2);
		
	}
Comment 7 Chris Goldthorpe CLA 2010-05-28 14:26:40 EDT
Returning to SWT team - I don't think the FormToolkit is the cause of the problem, I recommend that this either be treated as an enhancement request to add a flag to allow the label to appear before the checkbox or closed as invalid since the code is not using a checkbox as designed.
Comment 8 Andrew Stevenson CLA 2011-01-25 13:00:25 EST
I have the same issue I think. I'm using Ubuntu Linux and the following code:

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);

		shell.setLayout(new GridLayout(1, false));
		
		Button button = new Button(shell, SWT.CHECK);
		button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
		
		shell.open();

		while (! shell.isDisposed()) {
			if (! display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

I don't get the whole rectangle to the right, just the first few pixels - screen shot to be attached in a minute. It only shows when the window it is in is the active window. It seems to disappear at other times.
Comment 9 Andrew Stevenson CLA 2011-01-25 13:01:21 EST
Created attachment 187549 [details]
Screen shot from sample code I just posted (Linux)
Comment 10 Andrew Stevenson CLA 2011-01-25 13:02:57 EST
(In reply to comment #8)
> I have the same issue I think. I'm using Ubuntu Linux and the following code:

And the version.txt from within swt.jar says version 3.655
Comment 11 Christoph Krüger CLA 2012-12-11 09:22:40 EST
We see the same annoying effect using SWT under AIX.
Comment 12 Victor Rubezhny CLA 2013-11-29 21:54:29 EST
I pushed a fix for the issue here: https://git.eclipse.org/r/19165

SWT/GTK org.eclipse.swt.widgets.Button class is changed to control the visibility of box, label and image widgets due ton hide all the three widgets in case of empty label and image at the same time.

This contribution complies with http://www.eclipse.org/legal/CoO.php
Comment 13 Victor Rubezhny CLA 2013-11-29 22:00:39 EST
Created attachment 237881 [details]
The image of fixed checkbox with empty label

Here's how my fixed check box should look in case of empty label and null-image.
Comment 14 Alexander Kurtakov CLA 2014-01-30 12:54:17 EST
I see the problem but even with your patch it doesn't fix the problem for me (on gtk2). What is more weird is that with gtk3 with or without your patch I don't see the problem.
Comment 15 Victor Rubezhny CLA 2014-01-30 13:17:46 EST
It's not weird that all may work fine in GTK3, but I cannot argue here, 'cause i'm a victim of bug #421127 at the moment (My eclipse's views are all empty when I'm starting my eclipse by default).

Regarding the use of GTK2, I need a bit of time to investigate the non-working fix (I've moved on f20 currently, while my last tests on the issue where done on f19 where GTK2 was the default... At least I thought it was default there).
Comment 16 Victor Rubezhny CLA 2014-01-30 16:49:47 EST
Yes, Andrey, you're correct. My previous patch set was working only if you're putting the lines of code like:

button.setText("");

or 

button.setImage(null);

right after the button is created.

When there are no such calls, the buggy effect stays the same as described above.

I've created a Patch Set 6 with the fixed Button.showWidget() method. So, you can test it with the code snipped from Comment #8 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=314815#c8).

Thanks for your review.
Comment 17 Victor Rubezhny CLA 2014-01-30 17:30:53 EST
Created attachment 239496 [details]
Luna, GTK3 and the Checkbox with empty label bug

Alexander! (Shame on me! I've called you as Andrey - Sorry for that)

The image attached shows this bug on my Luna and GTK3. It's reproduced, as you can see. My patch set 6 solves the issue also on GTK3... At least in my environment.
Comment 18 Alexander Kurtakov CLA 2014-02-12 02:08:36 EST
(In reply to Victor Rubezhny from comment #17)
> Created attachment 239496 [details]
> Luna, GTK3 and the Checkbox with empty label bug
> 
> Alexander! (Shame on me! I've called you as Andrey - Sorry for that)
> 
> The image attached shows this bug on my Luna and GTK3. It's reproduced, as
> you can see. My patch set 6 solves the issue also on GTK3... At least in my
> environment.

Hi Victor,
Thanks for the patch. Works good for me and I pushed it to master http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=b2170202dd439d59048cdf10292188058b2ca5b9 . 
Keep them coming :).
Comment 19 Alexander Kurtakov CLA 2014-02-14 03:46:34 EST
Small additional fix unbreaking images showing for push buttons.
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=d18da1a6a32433411174b2025f6381c1db547bb7
Comment 20 Victor Rubezhny CLA 2014-02-14 04:56:26 EST
(In reply to Alexander Kurtakov from comment #19)
> Small additional fix unbreaking images showing for push buttons.
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=d18da1a6a32433411174b2025f6381c1db547bb7

Thanks for this, Alexander!