ColorDialog colorDialog= new ColorDialog(foregroundButton.getShell()); colorDialog.setRGB(chosenForegroundColor); RGB newColor = colorDialog.open(); if (newColor != null) { Color oldColor = null; if (foregroundColor != null) oldColor = foregroundColor; foregroundColor = new Color (foregroundButton.getDisplay(), newColor); GC gc= new GC(foregroundImage); gc.setBackground(foregroundColor); gc.fillRectangle(0,0,fontHeight*2-1,fontHeight-1); gc.drawRectangle(0,0,fontHeight*2-1,fontHeight-1); gc.dispose(); foregroundButton.setImage(foregroundImage); chosenForegroundColor = newColor; setColors (); if (oldColor != null) oldColor.dispose (); }
RGB rgb = foregroundDialog.open(); if (rgb == null) return; Color oldColor = foregroundColor; foregroundColor = new Color (foregroundButton.getDisplay(), rgb); setExampleWidgetForeground (); if (oldColor != null) oldColor.dispose ();
			public void widgetSelected(SelectionEvent event) {				ColorDialog colorDialog= new ColorDialog(foregroundButton.getShell());				colorDialog.setRGB(chosenForegroundColor);				RGB newColor = colorDialog.open();				if (newColor != null) {					Color oldColor = null;					if (foregroundColor != null) oldColor = foregroundColor;					foregroundColor = new Color (foregroundButton.getDisplay(), newColor);					GC gc= new GC(foregroundImage);					gc.setBackground(foregroundColor);					gc.fillRectangle(0,0,fontHeight*2-1,fontHeight-1);					gc.drawRectangle(0,0,fontHeight*2-1,fontHeight-1);					gc.dispose();					foregroundButton.setImage(foregroundImage);					chosenForegroundColor = newColor;					setColors ();					if (oldColor != null) oldColor.dispose ();				}			}