Menu

HowToSWT

Remo

SWT

HowTo: debug swt layouts
HowTo: manipulate layout data
HowTo: show hidden controls
HowTo: debug a dialog
HowTo: manipulate properties and members

[HowTo]: debug swt layouts

Sometimes the configured layout seems not the same as expected or presented in the running application. The following picture shows an example where the layout actually seems to be correct implemented. It’s a normal GridLayout?. But actually the Street/Number: seems to be somehow corrupt.

Such layout abnormalities are often the result of invisible controls which waste space. Use for debugging layouts either the Yari -> Paint! menu or hover on the composite and press ctrl+alt+v. The menu contribution will paint the whole workbench in different colors. The Key shortcut will only paint the control under the mouse cursor.

The black rectangle with the grey dotted border is in that case a label which is invisible, but still included in the layout (for GridLayout? GridData?.exclude will do the trick).

[HowTo]: manipulate layout data

You may want to change the layout constraints at runtime without restarting the whole application all the time? You can either start your eclipse application in debug mode, change the sourcecode, close the view and reopen it. The changes should be available now. Or you use the SWT-Inspector View and inspect and change the widgets at runtime.

Firstname should also grab the whole horizontal space:

Enable capturing -> select the textfield -> go to the “Member” tab and search for “layoutData” -> expand it and change the value of the GridData? “horizontalAligment” flag to “SWT.FILL” (4). Open the context menu on Text{} and select “update control”:

Note: this is only an inspection tool. The changes will not be written to the sourcecode.

[HowTo]: show hidden controls

Normally a captured control will be painted with cyan background and a black border. If you select a control which is hidden by others the cyan foregroundcolor will not be visible. Use therefore the “show widget position” in the swt inspector control tree:

The widget position will be visible by painting a red rectangle at the top of the shell:

[HowTo]: debug a dialog

If you need to debug a dialog which is application modal you cannot use the SWT Inspector view. Open the dialog and use the following shortcut: ctrl+alt+- This will open a new inspection dialog with the composite selected which was under the cursor.

[HowTo]: manipulate properties and members

You can use the SWT Inspector for manipulating widgets by calling the property method (on the Object-Tab) or by setting the value directly to the member variable using reflection (Member-Tab). Setting the value by using the properties will call the method and therefore normally change events will be fired. Setting the value direct to the member variable will not fire any change events. If you need to see the changes you need to use the update control action in the context menu.


Related

Documentation: Home
Documentation: HowTo

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.