Search code examples
javaswtcontrolsdirectoryctabitem

SWT CTabItem meaning of setData and setControl


I started with SWT programming and I am trying to reprogram this example, where CTabItem's are created within a CTabFolder. But since I am a very noob in GUI programming, some things are very unclear to me.

What is the purpose of setData() and setControl() for a CTabItem? In which cases or for which situations I use these methods? I have read the API documentation for setData, which says:

Sets the application defined widget data associated with the receiver to be the argument. The widget data is a single, unnamed field that is stored with every widget.

But I don't understand this and also the documentation for setControl. Can anyone please explain me the purpose of these methods?


Solution

  • The setData(Object) and setData(String, Object) methods are used to add additional data to a Widget. This data can later be accessed. Examples for this use are if you want to identify the widget later on or if you need this additional information someplace else.

    The setControl(Control) method assigns the content to the item. This means if you call item.setControl(myContent), this myContent will be shown if item is selected by the user.


    Example answers that suggest using setData():