CODEXE

SWT color dialog

swt color dialog

SWT Color Dialog

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;


public class Test {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Display d = new Display();
		Shell s = new Shell(d);
		s.setSize(100, 100);
		s.setLayout(new FillLayout(SWT.VERTICAL));
		Label b = new Label(s, SWT.BORDER);
		b.setText("Color...");
		b.addMouseListener(new MouseListener() {

			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
	
			@Override
			public void mouseDown(MouseEvent e) {
				// TODO Auto-generated method stub
				ColorDialog cd = new ColorDialog(s);
				cd.setText("Color...");
				cd.setRGB(new RGB(255, 255, 255));
				RGB colorSelected = cd.open();
				if (colorSelected == null) {
				  return;
				}
				b.setBackground(new Color(d, colorSelected));
			  
			}
	
			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		s.open();

		while (!s.isDisposed()) {
		  if (!d.readAndDispatch())
			d.sleep();
		}
		d.dispose();
	  
	}
}