⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renamedialog.java

📁 RSS一般理解为Rich Site Summary的所写
💻 JAVA
字号:
package mynews;

import java.awt.Toolkit;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class RenameDialog extends Dialog {

	private Text text;
	protected Object result;
	protected Shell shell;

	/**
	 * Create the dialog
	 * @param parent
	 * @param style
	 */
	public RenameDialog(Shell parent, int style) {
		super(parent, style);
	}

	/**
	 * Create the dialog
	 * @param parent
	 */
	public RenameDialog(Shell parent) {
		this(parent, SWT.NONE);
	}

	/**
	 * Open the dialog
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return result;
	}

	/**
	 * Create contents of the dialog
	 */
	protected void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setSize(382, 123);
		Toolkit kit = Toolkit.getDefaultToolkit();
		shell.setLocation((kit.getScreenSize().width - 382) / 2, (kit.getScreenSize().height - 123) / 2);

		shell.setText("Rename Dialog");

		final Label enterANewLabel = new Label(shell, SWT.NONE);
		enterANewLabel.setText("Enter a new name:");
		enterANewLabel.setBounds(15, 25, 108, 25);

		text = new Text(shell, SWT.BORDER);
		text.setBounds(125, 20, 236, 25);

		final Button okButton = new Button(shell, SWT.NONE);
		okButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if (text.getText() == null || text.getText().equals(""))
					return;
				result = text.getText();
				shell.close();
			}
		});
		okButton.setText("OK");
		okButton.setBounds(205, 65, 77, 24);

		final Button cancelButton = new Button(shell, SWT.NONE);
		cancelButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				result = null;
				shell.close();
			}
		});
		cancelButton.setBounds(288, 65, 77, 24);
		cancelButton.setText("Cancel");
		//
	}

}

⌨️ 快捷键说明

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