import java.util.ArrayList;
public class ShellDialog extends Shell {
/**
* Launch the application.
*
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
ShellDialog shell = new ShellDialog(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
*
* @param display
*/
public ShellDialog(Display display) {
super(display, SWT.NONE);
createContents();
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(450, 300);
setLayout(new GridLayout(2, false));
Label lblNewLabel = new Label(this, SWT.NONE);
lblNewLabel.setText("Dialog Title");
Button buttonClose = new Button(this, SWT.NONE);
buttonClose.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ShellDialog.this.dispose();
}
});
buttonClose.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
buttonClose.setText("X");
ListViewer viewer = new ListViewer(this);
org.eclipse.swt.widgets.List list = viewer.getList();
GridData gd_list = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
gd_list.widthHint = 29;
list.setLayoutData(gd_list);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new LabelProvider());
List<String> variables = new ArrayList<>();
variables.add("Broccoli");
variables.add("Bundt Cake");
variables.add("Cabbage");
variables.add("Candy Canes");
variables.add("Eggs");
variables.add("Potato Chips");
variables.add("Milk");
variables.add("Soda");
variables.add("Chicken");
variables.add("Cinnamon Rolls");
viewer.setInput(variables);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}