Get Selected Color from ColorDialog : ColorDialog « SWT « Java Tutorial






Get Selected Color from ColorDialog
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ColorDialogCreateGetColor {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    ColorDialog dlg = new ColorDialog(shell);
    RGB rgb = dlg.open();
    if (rgb != null) {
      Color color = new Color(shell.getDisplay(), rgb);
      
      System.out.println(color.getRGB());
      
      color.dispose();
    }

    display.dispose();
  }
}








17.103.ColorDialog
17.103.1.Choosing a Color
17.103.2.Get Selected Color from ColorDialogGet Selected Color from ColorDialog
17.103.3.Customizing the Color Selection DialogCustomizing the Color Selection Dialog
17.103.4.Set Label Background to a color selected in ColorDialogSet Label Background to a color selected in ColorDialog