Project: SWT
Bug 206894 Linux - Control.setEnabled disables more than it should
Reported: 2007-10-19 10:34:09 | Status: resolved fixed

Build ID: M20060629-1905 Steps To Reproduce: Run the following SWT program. The button in the first column of the table and the text field in the second column should operate such that if the button is selected, the text field in the same row is enabled. If the button isn't selected, the text field is disabled. The problem is on Linux if you unselect the button in the second row, it disables both the text field in its row, and the one in the first row. The problem appears to be the code in the Control.setEnabled between if (isDisposed ()) return; and if (fixFocus) fixFocus (control); As a test when I comment this code out it works as expected. More information: import java.util.Vector; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableEditor; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.widgets.FormToolkit; public class LinuxControl { public static Text conn1Text = null; public static Text conn2Text = null; public static void main(String [] args) { Vector buttonVector = new Vector(); Vector textVector = new Vector(); Display display = new Display (); Shell shell = new Shell (display); FormToolkit toolkit = new FormToolkit(shell.getDisplay()); shell.setLayout (new FillLayout ()); Table connTypeTable = new Table(shell, SWT.BORDER | SWT.MULTI); TableLayout tLayout = new TableLayout(); GridData data = new GridData(GridData.FILL_HORIZONTAL); connTypeTable.setLayoutData(data); connTypeTable.setLinesVisible(true); connTypeTable.setHeaderVisible(true); String [] headers = { "header1", "header2", "header3", "header4" }; for (int i = 0; i < headers.length; i++) { TableColumn column = new TableColumn(connTypeTable, SWT.NONE); column.setText(headers[i]); } connTypeTable.setLayout(tLayout); final Button conn1Check = toolkit.createButton(connTypeTable, "ConnType1", SWT.CHECK); conn1Check.setSelection(true); conn1Check.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { conn1Text.setEnabled(conn1Check.getSelection()); } }); buttonVector.add(conn1Check); conn1Text = new Text(connTypeTable, SWT.NONE); textVector.add(conn1Text); conn1Text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent me) { } }); final Button conn2Check = toolkit.createButton(connTypeTable, "ConnType2", SWT.CHECK); conn2Check.setSelection(true); conn2Check.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { conn2Text.setEnabled(conn2Check.getSelection()); } }); buttonVector.add(conn2Check); conn2Text = new Text(connTypeTable, SWT.NONE); textVector.add(conn2Text); conn1Text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent me) { } }); TableItem [] tableItems = new TableItem[2]; for (int i = 0; i < tableItems.length; i++) { tableItems[i] = new TableItem(connTypeTable, SWT.NONE); for (int j = 0; j < 4; j++) { if (j == 0) { TableEditor editor = new TableEditor(connTypeTable); Button button = (Button) buttonVector.get(i); button.setBackground(connTypeTable.getBackground()); editor.grabHorizontal = true; editor.setEditor(button, tableItems[i], j); } else if (j == 1) { TableEditor editor = new TableEditor(connTypeTable); editor.grabHorizontal = true; Text text = (Text) textVector.get(i); text.pack(); editor.setEditor(text, tableItems[i], j); } else if (j == 2) { tableItems[i].setText(j, "djakljdkla"); } else { tableItems[i].setText(j, "adadadfadfa"); } connTypeTable.getColumn(j).pack(); } } connTypeTable.pack(); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java