Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to create toolstrip using SWT?

Posted on 2013-06-06
2
Medium Priority
?
444 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses

609 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