|
タブはTabFolderクラスを使う。
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem;
TabFolder tab = new TabFolder(parent, SWT.NONE); tab.setLayoutData(new GridData(GridData.FILL_BOTH)); { // 1つめのタブ TabItem item = new TabItem(tab, SWT.NONE); item.setText("タブ1"); Composite composite = new Composite(tab, SWT.NONE); composite.setLayout(new GridLayout()); item.setControl(composite); Label label = new Label(composite, SWT.NONE); label.setText("ラベル1"); } { // 2つめのタブ TabItem item = new TabItem(tab, SWT.NONE); item.setText("タブ2"); Composite composite = new Composite(tab, SWT.NONE); composite.setLayout(new GridLayout()); item.setControl(composite); Label label = new Label(composite, SWT.NONE); label.setText("ラベル2"); }
タブページ全体はTabFolderで作る。
各タブはTabItemで作る。
タブページの内容は、別途Compositeを作って実現する。Compositeにコンポーネント(LabelやText等)を配置していく。
Compositeの親はTabFolderになる。
TabItem#setControl()でCompositeを登録する。
タブが選択されたときのイベントを取得する方法。
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener;
TabFolder tab = 〜; tab.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { TabFolder tab = (TabFolder) e.getSource(); System.out.println(tab.getSelectionIndex()); } @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } });