poniedziałek, 28 lipca 2014

How to implement onSelectionChange listener on CTabItem tabs of the CTabFolder widget

On the first glance there is no easy way for running arbitrary piece of code once one of the CTabItem tab is changed. Lucky there is generic addListener(int eventType, Listener listener) delivered with Widget class.
CTabItem item = new CTabItem(tabFolder, SWT.NULL);
Composite container = createContent(item.getParent());

item.addListener(SWT.SELECTED, new Listener() {

 public void handleEvent(Event event) {
But by default there is no such an event notified by CTabFolder. That is why we need take care of it.
tabFolder.addSelectionListener(new SelectionAdapter() {
 public void widgetSelected(SelectionEvent e) {
  tabFolder.getSelection().notifyListeners(SWT.SELECTED, new Event());
Thats all. Works like a charm ;)

Brak komentarzy:

Prześlij komentarz