Skip to content

Commit aa30ff0

Browse files
committed
Delay call to addListener in constructors of CCombo and StyledText #2733
The method is not final, which may cause issues if a subclass overrides it because it ends up being called upon instantiation, when the object is not fully initialized. Fixes #2733
1 parent 136b375 commit aa30ff0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ public CCombo (Composite parent, int style) {
173173
}
174174

175175
initAccessible();
176-
addListener(SWT.ZoomChanged, this::handleDPIChange);
176+
177+
// Add listener asynchronously in order to delay execution.
178+
// See https://github.com/eclipse-platform/eclipse.platform.swt/issues/2733
179+
getDisplay().asyncExec(() -> {
180+
checkWidget();
181+
addListener(SWT.ZoomChanged, this::handleDPIChange);
182+
});
177183
}
178184
static int checkStyle (int style) {
179185
int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT | SWT.LEAD | SWT.CENTER | SWT.TRAIL;

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,13 @@ public StyledText(Composite parent, int style) {
758758
initializeAccessible();
759759
setData("DEFAULT_DROP_TARGET_EFFECT", new StyledTextDropTargetEffect(this));
760760
if (IS_MAC) setData(STYLEDTEXT_KEY);
761-
addListener(SWT.ZoomChanged, this::handleDPIChange);
761+
762+
// Add listener asynchronously in order to delay execution.
763+
// See https://github.com/eclipse-platform/eclipse.platform.swt/issues/2733
764+
getDisplay().asyncExec(() -> {
765+
checkWidget();
766+
addListener(SWT.ZoomChanged, this::handleDPIChange);
767+
});
762768
}
763769
/**
764770
* Adds an extended modify listener. An ExtendedModify event is sent by the

0 commit comments

Comments
 (0)