Solved

How to place an icon in the center in a toolbar in SWT?

Posted on 2013-06-19
1
289 Views
Last Modified: 2013-06-21
I am working on a GUI and an icon that I use in the toolbar is not in the center.

How can I put the icon in the center? I am sending a screen shot in the attachment.

This is the code that I use to add this icon:

        CustomToolbar custToolBar11 = new CustomToolbar(compTB1, SWT.FLAT, "Configuration");
        
        item12 = new ToolItem(custToolBar11.getToolBar(), SWT.NONE);
        item12.setImage(image_floppy_disk); item12.setText("Save"); item12.setToolTipText("Sthg");

Open in new window


And this is the CustomToolbar class that I use:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;


public class CustomToolbar extends Composite {
    private ToolBar toolBar;
    private Label caption;
       
    public CustomToolbar(Composite parent, int style, String toolBarCaption) {
        super(parent, style);
        Font font = new Font(parent.getDisplay(),"Arial",10,SWT.ITALIC);
        final Color lightgray;
        lightgray = new Color (parent.getDisplay(), 140, 140, 140);
        
        setLayout(new GridLayout());
        toolBar = new ToolBar(this, SWT.FLAT);
        caption = new Label(this, SWT.HORIZONTAL | SWT.CENTER);
        caption.setText(toolBarCaption);
        caption.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // center the caption 
        caption.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
        caption.setForeground(lightgray);
        caption.setFont(font);
        toolBar.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
        setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    }

    public ToolBar getToolBar() {
        return toolBar;
    }

    public Label getCaption() {
        return caption;
    }

}

Open in new window

icon-center.png
0
Comment
Question by:Tolgar
1 Comment
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39264337
right after instantiation of toolBar add this two lines:

GridData tbGD = new GridData(); tbGD.horizontalAlignment = SWT.CENTER;
toolBar.setLayoutData(tbGD);
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

685 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