Java – Get Active Tab in SWT TabFolder

javaswtuser-interface

I apologize if this question is too basic, but I just can't figure out how to do this. I have a SWT TableFolder with two tabs, and I need to determine which of those two tabs are currently active, as it effects the behavior of another part of the program. Is this possible? Thank you in advance.

Best Solution

To you mean the org.eclipse.swt.widgets.TabFolder (CTabFolder)?

If yes add an eventlistener to your TabFolder(CTabFolder object

tabFolder.addSelectionListener(new SelectionAdapter() {
  public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
    tabFolder.getSelection()[0]; // This should be your TabItem/CTabItem
  }
});

If you simply have a javax.swing.JTabbedPane then calling

yourJTabbedPaneVariableName.getSelectedIndex()

gives you the index of the selected Tab