Skip to content

ColorButton

greipadmin edited this page Jan 31, 2017 · 27 revisions

Example 1

	...
	final ColorButton colorButton = new ColorButton(shell);
	colorButton.setText("Click me!");

	// initialize with current background rgb
	colorButton.setRGB(shell.getBackground().getRGB());

	colorButton.addListener(SWT.Selection, e -> {
		final RGB rgb = colorButton.chooseRGB(p -> new ColorChooserHSB(p, ColorResolution.Medium, true));
		// check if new color selected
		if (rgb != null) {
			// set new color to shell background
			final Color color = new Color(display, rgb);
			shell.setBackground(color);
			color.dispose();
		}
	});
	...
Clone this wiki locally