Code similar to the eclipse welcome window-formlayout typical example

Source: Internet
Author: User

A code similar to the eclipse welcome window

A background image with a progress bar at the bottom and a label on it to display some information.

Technical points:

I. Center the window

Ii. form layout

3. swt ui Thread Scheduling (this example implements a false one). Note that only the UI thread can operate the UI control.

In other Windows systems, new welcomewindow (). open () is enabled. After the loading task is executed in Windows, it is automatically disabled.

/** * Welcome Window */public class WelcomeWindow {//private static Logger logger = LoggerFactory.getLogger(WelcomeWindow.class);private Shell shell;/** * Open the window. */public void open() {Display display = Display.getDefault();createContents();configureShell();shell.open();// shell.layout();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}}/** * Configure shell *  * @param shell */protected void configureShell() {shell.pack();Rectangle rctDisplay = shell.getDisplay().getBounds();Rectangle rctShell = shell.getBounds();int x = (rctDisplay.width - rctShell.width) / 2;int y = (rctDisplay.height - rctShell.height) / 2;shell.setLocation(x, y);}/** * Create contents of the window. */protected void createContents() {shell = new Shell(SWT.ON_TOP);shell.setLayout(new FillLayout());// Composite as containerComposite container = new Composite(shell, SWT.NONE);FormLayout layout = new FormLayout();container.setLayout(layout);// ProgressBarfinal ProgressBar bar = new ProgressBar(container, SWT.HORIZONTAL);bar.setMinimum(0);bar.setMaximum(100);final int min = bar.getMinimum();final int max = bar.getMaximum();FormData formData = null;formData = new FormData();formData.left = new FormAttachment(0, 0);formData.right = new FormAttachment(100, 0);formData.bottom = new FormAttachment(100, 0);bar.setLayoutData(formData);// Label Messagefinal Label lblMessage = new Label(container, SWT.INHERIT_DEFAULT);lblMessage.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));formData = new FormData();formData.left = new FormAttachment(0, 0);formData.right = new FormAttachment(60);formData.bottom = new FormAttachment(bar, 0);lblMessage.setLayoutData(formData);// Label ImageLabel lblImage = new Label(container, SWT.NONE);lblImage.setImage(Registry.getImage("logo.bmp"));formData = new FormData();formData.left = new FormAttachment(0, 0);formData.top = new FormAttachment(0, 0);lblImage.setLayoutData(formData);final int step = 5;new Thread(new Runnable() {public void run() {shell.getDisplay().asyncExec(new Runnable() {public void run() {for (int i = min; i < max; i += step) {if (bar.isDisposed()) {return;}try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}String text = GlobalVariable.getResourceBundle().getString("ww.bar.loading");text = MessageFormat.format(text, bar.getSelection(), StringUtils.repeat('.', i / step));lblMessage.setText(text);bar.setSelection(bar.getSelection() + i);}shell.dispose();}});}}).start();}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.