Skip to content

Commit 200934c

Browse files
Adding a recommendation for the usage of setLocation in Control
Setting the location of the control before setting its size could cause a DPI_CHANGE event in win32 since the OS is responsible for providing the size to the control upon creation and this size can be very big, causing the control to span across multiple monitors.
1 parent 63048a2 commit 200934c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,10 @@ public void setLayoutData (Object layoutData) {
39913991
* @param x the new x coordinate for the receiver
39923992
* @param y the new y coordinate for the receiver
39933993
*
3994+
* <p><strong>Recommended Usage:</strong> If you plan to use {@link #setSize(int, int)},
3995+
* call it <em>before</em> calling this method. This ensures the control is sized
3996+
* correctly before positioning, which helps avoid layout issues when using absolute positioning.</p>
3997+
*
39943998
* @exception SWTException <ul>
39953999
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
39964000
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -4013,6 +4017,10 @@ public void setLocation (int x, int y) {
40134017
*
40144018
* @param location the new location for the receiver
40154019
*
4020+
* <p><strong>Recommended Usage:</strong> If you plan to use {@link #setSize(int, int)},
4021+
* call it <em>before</em> calling this method. This ensures the control is sized
4022+
* correctly before positioning, which helps avoid layout issues when using absolute positioning.</p>
4023+
*
40164024
* @exception SWTException <ul>
40174025
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
40184026
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,10 @@ Point getLocationInPixels () {
12601260
*
12611261
* @param location the new location for the receiver
12621262
*
1263+
* <p><strong>Recommended Usage:</strong> If you plan to use {@link #setSize(int, int)},
1264+
* call it <em>before</em> calling this method. This ensures the control is sized
1265+
* correctly before positioning, which helps avoid layout issues when using absolute positioning.</p>
1266+
*
12631267
* @exception SWTException <ul>
12641268
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
12651269
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -1290,6 +1294,10 @@ void setLocationInPixels (Point location) {
12901294
* @param x the new x coordinate for the receiver
12911295
* @param y the new y coordinate for the receiver
12921296
*
1297+
* <p><strong>Recommended Usage:</strong> If you plan to use {@link #setSize(int, int)},
1298+
* call it <em>before</em> calling this method. This ensures the control is sized
1299+
* correctly before positioning, which helps avoid layout issues when using absolute positioning.</p>
1300+
*
12931301
* @exception SWTException <ul>
12941302
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
12951303
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,8 +3504,9 @@ public void setLayoutData (Object layoutData) {
35043504
* intended effect on some platforms. For example, executing this operation on a
35053505
* shell when the environment uses the Wayland protocol, nothing will happen.
35063506
*
3507-
* @param x the new x coordinate for the receiver
3508-
* @param y the new y coordinate for the receiver
3507+
* <p><strong>Recommended Usage:</strong> If you plan to use {@link #setSize(int, int)},
3508+
* call it <em>before</em> calling this method. This ensures the control is sized
3509+
* correctly before positioning, which helps avoid layout issues when using absolute positioning.</p>
35093510
*
35103511
* @exception SWTException <ul>
35113512
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -3537,6 +3538,10 @@ void setLocationInPixels (int x, int y) {
35373538
*
35383539
* @param location the new location for the receiver
35393540
*
3541+
* <p><strong>Recommended Usage:</strong> If you plan to use {@link #setSize(int, int)},
3542+
* call it <em>before</em> calling this method. This ensures the control is sized
3543+
* correctly before positioning, which helps avoid layout issues when using absolute positioning.</p>
3544+
*
35403545
* @exception SWTException <ul>
35413546
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
35423547
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

0 commit comments

Comments
 (0)