📄 sendmessagedialog.java
字号:
package com.face;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* 自定义对话框类
* @param parent
* @return
*/
public class SendMessageDialog extends Dialog {
private String textValue; //文本框内容
private Text writeText; //文本实例
/**
* 构造函数
* @param parentShell
*/
public SendMessageDialog(Shell parentShell) {
super(parentShell);
}
/**
* 构建Dialog中的界面内容
* @param parent
* @return
*/
protected Control createDialogArea(Composite parent) {
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setLayout(new RowLayout());
new Label(topComp, SWT.NONE).setText("请输入:");
writeText = new Text(topComp, SWT.BORDER|SWT.V_SCROLL|SWT.WRAP);
writeText.setLayoutData(new RowData(350, 200));
writeText.setText(textValue == null ?"" :textValue);
return topComp;
}
/**
* 可以改变窗口的默认样式
*/
protected int getShellStyle() {
return super.getShellStyle()|SWT.MAX;
}
/**
* 取得文本内容
* @return String 文本内容
*/
protected String getTextValue() {
return this.textValue;
}
/**
* 设置文本内容
* @param str 文本内容
*/
protected void setTextValue(String str) {
this.textValue = str;
}
/**
* 单击确定按钮
*/
protected void buttonPressed(int buttonId) {
//如果点了OK按钮,则将值取回变量
if(buttonId == IDialogConstants.OK_ID) {
textValue = writeText.getText();
}
super.buttonPressed(buttonId);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -