packagedev.equo;importorg.eclipse.swt.SWT;importorg.eclipse.swt.graphics.Color;importorg.eclipse.swt.graphics.GC;importorg.eclipse.swt.graphics.Image;importorg.eclipse.swt.graphics.ImageData;importorg.eclipse.swt.graphics.PaletteData;importorg.eclipse.swt.graphics.RGB;importorg.eclipse.swt.layout.GridData;importorg.eclipse.swt.layout.GridLayout;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Label;importorg.eclipse.swt.widgets.Shell;importorg.eclipse.swt.widgets.TabFolder;importorg.eclipse.swt.widgets.TabItem;/** * TabFolder tabs with no image, with an image painted with a GC, and with an image built from * pixel data, on a TOP and on a BOTTOM folder. Uses the public SWT API only, so the same class * runs on native SWT for comparison. */publicclassTabFolderImagesSnippet{/** A 16x16 image painted with a GC: an orange disc with a dark ring. */staticImagegcImage(Displaydisplay){Imageimage=newImage(display,16,16);GCgc=newGC(image);gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));gc.fillRectangle(0,0,16,16);gc.setBackground(newColor(display,240,140,20));gc.fillOval(1,1,14,14);gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));gc.drawOval(1,1,13,13);gc.dispose();returnimage;}/** A 16x16 image built from pixel data only: a green square with a blue diagonal. */staticImagebytesImage(Displaydisplay){PaletteDatapalette=newPaletteData(0xFF0000,0x00FF00,0x0000FF);ImageDatadata=newImageData(16,16,24,palette);intgreen=palette.getPixel(newRGB(30,170,60));intblue=palette.getPixel(newRGB(20,60,220));for(inty=0;y<16;y++){for(intx=0;x<16;x++){data.setPixel(x,y,Math.abs(x-y)<=1?blue:green);}}returnnewImage(display,data);}staticTabFolderfolder(Shellshell,intstyle,Imagegc,Imagebytes,intselected){TabFolderfolder=newTabFolder(shell,style);folder.setLayoutData(newGridData(SWT.FILL,SWT.FILL,true,true));String[]names={"Plain","GC image","Bytes image"};Image[]images={null,gc,bytes};for(inti=0;i<names.length;i++){TabItemitem=newTabItem(folder,SWT.NONE);item.setText(names[i]);if(images[i]!=null)item.setImage(images[i]);Labelpage=newLabel(folder,SWT.NONE);page.setText("Page of \""+names[i]+"\"");item.setControl(page);}folder.setSelection(selected);returnfolder;}publicstaticShellcreate(Displaydisplay){Shellshell=newShell(display);shell.setText("TabFolderImagesSnippet");shell.setLayout(newGridLayout());Imagegc=gcImage(display);Imagebytes=bytesImage(display);TabFolderplain=newTabFolder(shell,SWT.TOP);plain.setLayoutData(newGridData(SWT.FILL,SWT.FILL,true,true));for(inti=1;i<=3;i++){TabItemitem=newTabItem(plain,SWT.NONE);item.setText("Plain "+i);Labelpage=newLabel(plain,SWT.NONE);page.setText("No tab has an image");item.setControl(page);}folder(shell,SWT.TOP,gc,bytes,1);folder(shell,SWT.BOTTOM,gc,bytes,2);shell.addDisposeListener(e->{gc.dispose();bytes.dispose();});shell.setSize(420,330);returnshell;}publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=create(display);shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}}
{@code Composite.setVisible(...)}, then {@code layout()}.
The reported bug: on the Flutter (web) backend the tab body switched but the preview never did,
because the Flutter tab click did not fire {@code SWT.Selection}, so this listener never ran. With
the fix the listener runs and the visible preview follows the selected tab.
Drive it on the web example and read the two panels' live {@code visible} state by id:
flutter-mcp launch TabFolderPreviewSwapSnippet ; flutter-mcp state
packagedev.equo;importdev.equo.swt.Config;importorg.eclipse.swt.SWT;importorg.eclipse.swt.events.SelectionAdapter;importorg.eclipse.swt.events.SelectionEvent;importorg.eclipse.swt.layout.GridData;importorg.eclipse.swt.layout.GridLayout;importorg.eclipse.swt.widgets.*;/** * Faithful stand-in for EGit's Git → Label Decorations preference page: a * {@link TabFolder} whose {@link SelectionListener} swaps a <em>dependent</em> "Preview:" area below * it. The two preview panels ({@code navigatorPreview}, {@code changeSetPreview}) are sibling * composites in a {@link GridLayout} parent; switching tabs hides one and shows the other using the * exact mechanism EGit's {@code Preview.show()/hide()} uses — toggle {@code GridData.exclude} and * {@code Composite.setVisible(...)}, then {@code layout()}. * * <p>The reported bug: on the Flutter (web) backend the tab body switched but the preview never did, * because the Flutter tab click did not fire {@code SWT.Selection}, so this listener never ran. With * the fix the listener runs and the visible preview follows the selected tab. * * <p>Drive it on the web example and read the two panels' live {@code visible} state by id: * <pre>flutter-mcp launch TabFolderPreviewSwapSnippet ; flutter-mcp state</pre> */publicclassTabFolderPreviewSwapSnippet{/** One preview panel: a composite that can be shown/hidden exactly like EGit's Preview. */staticfinalclassPreview{finalCompositecomposite;Preview(Compositeparent,Stringcaption){composite=newComposite(parent,SWT.NONE);composite.setLayout(newGridLayout());composite.setLayoutData(newGridData(SWT.FILL,SWT.FILL,true,true));Labellabel=newLabel(composite,SWT.NONE);label.setText(caption);}voidshow(){((GridData)composite.getLayoutData()).exclude=false;composite.setVisible(true);composite.getParent().layout();}voidhide(){((GridData)composite.getLayoutData()).exclude=true;composite.setVisible(false);composite.getParent().layout();}}publicstaticvoidmain(String[]args){Config.useEquo(TabFolder.class);Config.useEquo(TabItem.class);Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("TabFolderPreviewSwapSnippet");shell.setLayout(newGridLayout());TabFolderfolder=newTabFolder(shell,SWT.TOP);folder.setLayoutData(newGridData(SWT.FILL,SWT.TOP,true,false));String[]tabs={"General","Other"};for(Stringname:tabs){TabItemitem=newTabItem(folder,SWT.NONE);item.setText(name);Textbody=newText(folder,SWT.MULTI|SWT.BORDER);body.setText(name+" tab content");item.setControl(body);}folder.setSelection(0);LabelpreviewCaption=newLabel(shell,SWT.NONE);previewCaption.setText("Preview:");// The dependent area: both panels stacked in a GridLayout parent; only one is shown at a time.CompositepreviewArea=newComposite(shell,SWT.BORDER);previewArea.setLayout(newGridLayout());previewArea.setLayoutData(newGridData(SWT.FILL,SWT.FILL,true,true));PreviewnavigatorPreview=newPreview(previewArea,"resources tree (Project / folder / tracked.txt)");PreviewchangeSetPreview=newPreview(previewArea,"commits preview ([Author] (date) message)");// Initial state mirrors the General tab: navigator shown, change set hidden.navigatorPreview.show();changeSetPreview.hide();folder.addSelectionListener(newSelectionAdapter(){@OverridepublicvoidwidgetSelected(SelectionEvente){booleanother=folder.getSelectionIndex()==1;System.out.println("Tab selected: "+folder.getSelectionIndex()+" -> showing "+(other?"changeSetPreview":"navigatorPreview"));if(other){navigatorPreview.hide();changeSetPreview.show();}else{changeSetPreview.hide();navigatorPreview.show();}}});shell.setSize(560,380);shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch()){display.sleep();}}display.dispose();}}
[View on GitHub :simple-github:](https://github.com/equodev/swt-evolve/blob/main/examples/src/main/java/dev/equo/TabFolderPreviewSwapSnippet.java){ .md-button }
### Snippet
[](assets/screenshots/TabFolderSnippet.png){.glightbox}
Demonstrates the use of TabFolder widget in SWT.
This example creates a tab folder with 6 tabs, each containing a text area with sample content.
The tab folder includes:
- Standard SWT tab navigation
- Selection events to track tab changes
- Multi-line text content in each tab with scrollbars
- Proper layout management
??? example "TabFolderSnippet.java"
packagedev.equo;importdev.equo.swt.Config;importorg.eclipse.swt.SWT;importorg.eclipse.swt.events.SelectionAdapter;importorg.eclipse.swt.events.SelectionEvent;importorg.eclipse.swt.layout.GridData;importorg.eclipse.swt.layout.GridLayout;importorg.eclipse.swt.widgets.*;/** * Demonstrates the use of TabFolder widget in SWT. * This example creates a tab folder with 6 tabs, each containing a text area with sample content. * The tab folder includes: * - Standard SWT tab navigation * - Selection events to track tab changes * - Multi-line text content in each tab with scrollbars * - Proper layout management */publicclassTabFolderSnippet{publicstaticvoidmain(String[]args){Config.useEquo(TabFolder.class);Config.useEquo(TabItem.class);Displaydisplay=newDisplay();finalShellshell=newShell(display);shell.setText("TabFolderSnippet");shell.setLayout(newGridLayout());// Create a TabFolder with border stylefinalTabFolderfolder=newTabFolder(shell,SWT.BORDER|SWT.TOP);folder.setLayoutData(newGridData(SWT.FILL,SWT.FILL,true,true));// Create tabsfor(inti=0;i<6;i++){TabItemitem=newTabItem(folder,SWT.NONE);item.setText("Tab "+i);item.setToolTipText("This is tab number "+i);// Create content for each tabTexttext=newText(folder,SWT.MULTI|SWT.V_SCROLL|SWT.H_SCROLL);text.setText("Content for Tab "+i+"\n\n"+"This is a multi-line text area.\n"+"You can add any content here.\n\n"+"Line 1\nLine 2\nLine 3\n\n"+"The TabFolder widget provides a simple\n"+"way to organize multiple pages of content.");item.setControl(text);}// Set initial selectionfolder.setSelection(0);// Add selection listener to track tab changesfolder.addSelectionListener(newSelectionAdapter(){@OverridepublicvoidwidgetSelected(SelectionEvente){System.out.println("Tab selected: "+folder.getSelectionIndex());}@OverridepublicvoidwidgetDefaultSelected(SelectionEvente){System.out.println("Tab double-clicked: "+folder.getSelectionIndex());}});shell.setSize(500,350);shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch()){display.sleep();}}display.dispose();}}
[View on GitHub :simple-github:](https://github.com/equodev/swt-evolve/blob/main/examples/src/main/java/dev/equo/TabFolderSnippet.java){ .md-button }