Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Re: How to add a icon to a Shell title bar

Chatura,

 

U can create an image in the following way

ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL("file:///E:/development/eclipse/plugins/org.eclipse.help.ui_2.1.1/icons/back.gif");

      Image image = imageDescriptor.createImage();

Then set it to the shell as follows

shell.setImage(image);

 

A complete test class of stand alone application is shown below.

Hope this will help u.

 

Hasith Yaggahavitahasithy@xxxxxxxxxxxxx

(Sri Lanka)

 

 

 

 

import java.net.MalformedURLException;

import java.net.URL;

 

import org.eclipse.jface.resource.ImageDescriptor;

import org.eclipse.jface.window.ApplicationWindow;

import org.eclipse.swt.graphics.Image;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Control;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

 

/*

 * Created on May 15, 2004

 *

 * To change the template for this generated file go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

 

/**

 * @author eurcolhya

 *

 * To change the template for this generated type comment go to

 * Window>Preferences>Java>Code Generation>Code and Comments

 */

public class TestWindow extends ApplicationWindow {

 

      /**

       * @param arg0

       */

      public TestWindow() {

            super(null);

      }

      protected Control createContents(Composite parent) {

            Shell shell = getShell();

            shell.setText("TestWindow");

            shell.setSize(200, 200);

            Image image = createImage();

            shell.setImage(image);

 

            return parent;

      }

      private Image createImage() {

            try {

                  URL url = new URL("file:///E:/development/eclipse/plugins/org.eclipse.help.ui_2.1.1/icons/back.gif");

                  ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);

                  Image image = imageDescriptor.createImage();

                  return image;

            } catch (MalformedURLException e) {

                  return null;

            }

      }

 

      public static void main(String[] args) {

            TestWindow w = new TestWindow();

            w.setBlockOnOpen(true);

            w.open();

            Display.getCurrent().dispose();

      }

}

 


Back to the top