The difference between the display and the shell

A typical SWT code example is as follows:

final Display display = Display.getDefault(); final Shell shell = createMyShell(display); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } 

What is the difference between Display and Shell ?
If you need to show multiple windows, does each one need a separate loop?

+4
source share
3 answers

Yes, if you need to show several windows (shells), you should have a loop for each of them.

But there is only one Display in the application that needs to be created.

+4
source

You can have multiple shells with one display and one-time event sending. Create a screen, create a shell from the screen, and start a single outline of the user interface event manager. See http://www.chrisnewland.com/av/111/swt-best-practice-single-display-multiple-shells

+6
source

ChrisWhoCodes is quite correct. The following code implements its model.

 import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class MultipleShells { public MultipleShells(Display display) { Shell[] shells; MainWindows mainWindow; mainWindow = new MainWindows(display, "Shell 1"); mainWindow = new MainWindows(display, "Shell 2"); while (!display.isDisposed()) { if (!display.readAndDispatch()) { shells = display.getShells(); if (shells.length == 0) break; display.sleep(); } } } public static void main(String[] args) { Display display = new Display(); MultipleShells mainApp = new MultipleShells(display); display.dispose(); } } class MainWindows { protected MainWindows(Display parent, String title) { Shell mainShell; mainShell = new Shell(parent); mainShell.setText(title); mainShell.open(); } } 
+1
source

All Articles