Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to create toolstrip using SWT?

Hi,
I have a GUI mockup which can be seen in the attachment. I am basically trying to create a toolstrip. For each of the 3 tabs I will get different set of icons on the toolstrip.

I have a code that creates the tabs and some icons for each tab but it does not look the same as the one that I have in the attachment.

Can you please tell me what changes I should make in my code to have the similar look with the one in the attachment?


import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;


public class Gui {
    public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);
               
        shell.setText("MY TOOL");
        shell.setLayout(new GridLayout());
        // SWT.BOTTOM to show at the bottom
        CTabFolder folder = new CTabFolder(shell, SWT.TOP);
        GridData data = new GridData(GridData.FILL,
                GridData.FILL, true, true,
                20, 10);
        folder.setLayoutData(data);
        CTabItem cTabItem1 = new CTabItem(folder, SWT.NONE);
        cTabItem1.setText("A");
        CTabItem cTabItem2 = new CTabItem(folder, SWT.NONE);
        cTabItem2.setText("B");
        CTabItem cTabItem3 = new CTabItem(folder, SWT.NONE);
        cTabItem3.setText("C");
               
        Composite compTab1 = new Composite(folder, SWT.NULL);      
        // Create the layout.
        RowLayout layout = new RowLayout();
        // Optionally set layout fields.
        layout.wrap = true;
        // Set the layout into the composite.
        // shell.setLayout(layout);
        // Create the children of the composite.
        FillLayout fillLayoutResults1 = new FillLayout();
        fillLayoutResults1.type = SWT.HORIZONTAL;
        new Button(compTab1, SWT.PUSH).setText("B1");
        new Button(compTab1, SWT.PUSH).setText("Wide Button 1");
        new Button(compTab1, SWT.PUSH).setText("Button 1");
               
        Text text = new Text(folder, SWT.BORDER);
        text.setText("You can type the list of files in this field");
        cTabItem1.setControl(text);
       
        compTab1.setLayout(layout);
        compTab1.setLayout(fillLayoutResults1);
        cTabItem1.setControl(compTab1);
       
        Composite compTab2 = new Composite(folder, SWT.NULL);
       
        FillLayout fillLayoutResults2 = new FillLayout();
        fillLayoutResults2.type = SWT.HORIZONTAL;
        Image image = new Image(display, "chart.png");      
        Button b2 = new Button(compTab2, SWT.PUSH); b2.setImage(image);
        Button b2Wide = new Button(compTab2, SWT.PUSH); b2Wide.setImage(image);
        Button buton2 = new Button(compTab2, SWT.PUSH); buton2.setImage(image); 
       
        compTab2.setLayout(fillLayoutResults2);
        cTabItem2.setControl(compTab2);
        
        Composite compTab3 = new Composite(folder, SWT.NULL);
        
        FillLayout fillLayoutResults3 = new FillLayout();
        fillLayoutResults3.type = SWT.HORIZONTAL;
        new Button(compTab3, SWT.PUSH).setText("B3");
        new Button(compTab3, SWT.PUSH).setText("Wide Button 3");
        new Button(compTab3, SWT.PUSH).setText("Button 3");
       
        compTab3.setLayout(fillLayoutResults3);
        cTabItem3.setControl(compTab3);
        
        
        shell.addShellListener(new ShellListener() {

            public void shellIconified(ShellEvent e) {
            }
            public void shellDeiconified(ShellEvent e) {
            }
            public void shellDeactivated(ShellEvent e) {
            }
            public void shellClosed(ShellEvent e) {
                System.out.println("Client Area: " + shell.getClientArea());
            }
            public void shellActivated(ShellEvent e) {
                int frameX = shell.getSize().x - shell.getClientArea().width;
                int frameY = shell.getSize().y - shell.getClientArea().height;
                shell.setSize(1200 + frameX, 1000 + frameY);
            }
        });     
             
        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
} 

Open in new window

A.png
B.png
C.png
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

Perfect solution!!