?
Solved

How to create toolstrip using SWT?

Posted on 2013-06-06
2
Medium Priority
?
440 Views
Last Modified: 2013-06-06
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
0
Comment
Question by:Tolgar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 2000 total points
ID: 39226582
check this, I added a menu only for tab 1, you can do the same for tab 2 and 3:

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.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
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");
       
        Image image = new Image(display, "chart.png");
       
        Composite compTab1 = new Composite(folder, SWT.NULL);
        RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
        compTab1.setLayout(rowLayout);
               
        ToolBar toolBar = new ToolBar(compTab1, SWT.FLAT);
       
               
        ToolItem item1 = new ToolItem(toolBar, SWT.PUSH);
        item1.setImage(image);
        new ToolItem(toolBar, SWT.SEPARATOR);
       
        ToolItem item2 = new ToolItem(toolBar, SWT.PUSH);
        item2.setImage(image);
        new ToolItem(toolBar, SWT.SEPARATOR);
       
        ToolItem item3 = new ToolItem(toolBar, SWT.PUSH);
        item3.setImage(image);
               
       
        Composite compButtons = new Composite(compTab1, SWT.NULL);
        FillLayout fillLayout = new FillLayout();
        fillLayout.type = SWT.HORIZONTAL;
               
        Button b1 = new Button(compButtons, SWT.PUSH); b1.setText("B1");
        Button b1Wide = new Button(compButtons, SWT.PUSH); b1Wide.setText("Wide Button 1");
        Button buton1 = new Button(compButtons, SWT.PUSH); buton1.setText("Button 1");
       
        compButtons.setLayout(fillLayout);
       
        cTabItem1.setControl(compTab1);
// -----------here starts TAB 2 --------------------      
        Composite compTab2 = new Composite(folder, SWT.NULL);
       
        FillLayout fillLayoutResults2 = new FillLayout();
        fillLayoutResults2.type = SWT.HORIZONTAL;
             
        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);
     // -----------here starts TAB 3 --------------------      
        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(600 + frameX, 500 + frameY);
            }
        });
             
        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}
0
 

Author Closing Comment

by:Tolgar
ID: 39226709
Perfect solution!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question