11package de .vogella .swt .widgets ;
22
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
36import org .eclipse .swt .SWT ;
47import org .eclipse .swt .graphics .Image ;
58import org .eclipse .swt .layout .GridLayout ;
@@ -16,7 +19,6 @@ public static void main(String[] args) {
1619 // setup the SWT window
1720 Display display = new Display ();
1821 final Shell shell = new Shell (display );
19- shell .setSize (520 , 200 );
2022 shell .setLayout (new RowLayout ());
2123 shell .setText ("Photo Application" );
2224
@@ -25,25 +27,34 @@ public static void main(String[] args) {
2527 // 4x columns
2628 Composite parent = new Composite (shell , SWT .NONE );
2729 GridLayout gridLayout = new GridLayout ();
28- gridLayout .numColumns = 4 ;
30+ gridLayout .numColumns = 7 ;
2931 parent .setLayout (gridLayout );
3032
31- // determine the path where the pictures are stored
32- String path = System .getProperty ("user.dir" ) + "/images/" ;
33- // initialize an array with the photograph names
34- String [] imgNames = new String [] { "lars.png" , "andre.png" ,
35- "matthias.png" , "arne.png" };
33+ // Get the Display default icons
34+ List <Image > imageList = new ArrayList <Image >();
35+
36+ imageList .add (Display .getDefault ().getSystemImage (SWT .ICON_CANCEL ));
37+ imageList .add (Display .getDefault ().getSystemImage (SWT .ICON_WARNING ));
38+ imageList .add (Display .getDefault ().getSystemImage (SWT .ICON_WORKING ));
39+ imageList .add (Display .getDefault ().getSystemImage (SWT .ICON_QUESTION ));
40+ imageList .add (Display .getDefault ().getSystemImage (SWT .ICON_SEARCH ));
41+ imageList
42+ .add (Display .getDefault ().getSystemImage (SWT .ICON_INFORMATION ));
43+ imageList .add (Display .getDefault ().getSystemImage (SWT .ICON_ERROR ));
3644
37- // loop over the photo array and establish all listeners
38- for (int i = 0 ; i < imgNames .length ; i ++) {
39- // labels serve as containers for the images
45+ // Alternative load images via
46+ // Image img = new Image(display, path + imgNames[i]);
47+ // to get a path
48+ // String path = System.getProperty("user.dir") + "/images/";
49+ for (Image image : imageList ) {
4050 Label label = new Label (parent , SWT .NONE );
41- Image img = new Image (display , path + imgNames [i ]);
42- label .setImage (img );
51+ label .setImage (image );
4352 }
44-
4553 // show the SWT window
54+
55+ shell .pack ();
4656 shell .open ();
57+
4758 while (!shell .isDisposed ()) {
4859 if (!display .readAndDispatch ())
4960 display .sleep ();
0 commit comments