Java by API/org.eclipse.swt.custom/PopupList

Материал из Java эксперт
Перейти к: навигация, поиск

new PopupList(Shell shell)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.custom.PopupList; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   
   final Display d = new Display();
   final Shell shell = new Shell(d);
   shell.setSize(250, 200);
   
   shell.setLayout(new RowLayout());
   Button button = new Button(shell, SWT.PUSH);
   button.setText("Push Me");
   button.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent event) {
       PopupList list = new PopupList(shell);
       String[] OPTIONS = { "A", "B", "C"};
       list.setItems(OPTIONS);
       String selected = list.open(shell.getBounds());
       System.out.println(selected);
     }
   });
   
   
   shell.open();
   while (!shell.isDisposed()) {
     if (!d.readAndDispatch())
       d.sleep();
   }
   d.dispose();
 }

}


      </source>
   
  
 
  



PopupList: open(Rectangle rect)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.custom.PopupList; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   
   final Display d = new Display();
   final Shell shell = new Shell(d);
   shell.setSize(250, 200);
   
   shell.setLayout(new RowLayout());
   Button button = new Button(shell, SWT.PUSH);
   button.setText("Push Me");
   button.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent event) {
       PopupList list = new PopupList(shell);
       String[] OPTIONS = { "A", "B", "C"};
       list.setItems(OPTIONS);
       String selected = list.open(shell.getBounds());
       System.out.println(selected);
     }
   });
   
   
   shell.open();
   while (!shell.isDisposed()) {
     if (!d.readAndDispatch())
       d.sleep();
   }
   d.dispose();
 }

}


      </source>
   
  
 
  



PopupList: setItems(String[] items)

   <source lang="java">

import org.eclipse.swt.SWT; import org.eclipse.swt.custom.PopupList; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class MainClass {

 public static void main(String[] a) {
   
   final Display d = new Display();
   final Shell shell = new Shell(d);
   shell.setSize(250, 200);
   
   shell.setLayout(new RowLayout());
   Button button = new Button(shell, SWT.PUSH);
   button.setText("Push Me");
   button.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent event) {
       PopupList list = new PopupList(shell);
       String[] OPTIONS = { "A", "B", "C"};
       list.setItems(OPTIONS);
       String selected = list.open(shell.getBounds());
       System.out.println(selected);
     }
   });
   
   
   shell.open();
   while (!shell.isDisposed()) {
     if (!d.readAndDispatch())
       d.sleep();
   }
   d.dispose();
 }

}


      </source>