usingcolordialog.java

来自「eclipse开发笔记」· Java 代码 · 共 49 行

JAVA
49
字号
package book.ch4;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class UsingColorDialog {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Display display = Display.getDefault();

		final Shell shell = new Shell(display);
		shell.setSize(200, 100);
		shell.open();

		Button button = new Button(shell, SWT.PUSH);
		button.setBounds(10, 10, 100, 20);
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				ColorDialog cd = new ColorDialog(shell);
				RGB rgb = cd.open();
				if (rgb != null) {
					Color color = new Color(Display.getDefault(), rgb);
					// Use Color
					color.dispose();
				}

			}
		});

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?