?? colordialogexample2.java
字號:
/**@author WangJinTao,MengQingChang 2006
*/
package swt.dialog;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
public class ColorDialogExample2 {
private Text text;
private Color color;
public ColorDialogExample2() {
final Display display = Display.getDefault();
final Shell shell = new Shell(new Shell());
shell.setSize(383, 225);
shell.setText("ColorDialog實例");
text = new Text(shell, SWT.BORDER);
text.setBounds(5, 5, 365, 150);
text.setText("SWT/JFace");
color = new Color(shell.getDisplay(), new RGB(0, 255, 0));
Button button = new Button(shell, SWT.PUSH);
button.setBounds(250, 165, 120, 20);
button.setText("顏色選擇對話框");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// 定義顏色選擇對話框
ColorDialog dlg = new ColorDialog(shell);
// 打開對話框
RGB rgb = dlg.open();
if (rgb != null) {
color = new Color(shell.getDisplay(), rgb);
// 設置前景顏色
text.setForeground(color);
/**
* 設置背景顏色 text.setBackground(color);
*/
}
}
});
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public static void main(String[] args) {
new ColorDialogExample2();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -