is the parent shell from the dialog the shell from the main?
here is my code
main:
- Code: Select all
public class GUIMain extends Shell {
public static void main(String args[]) {
try {
Display display = Display.getDefault();
GUIMain shell = new GUIMain(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public GUIMain(Display display, int style) {
super(display, style);
createContents();
}
protected void createContents() {
setText("SWT Application");
setSize(500, 375);
setLayout(new RowLayout());
final Button button = new Button(this, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
GUIPersonPicker pp = new GUIPersonPicker(getParent().getShell());
pp.createContents();
}
});
button.setText("PersonPicker");
}
protected void checkSubclass() {
}
}
dialog:
- Code: Select all
public class GUIPersonPicker extends Dialog {
private Table table_1;
private Text text_1;
protected Object result;
protected Shell shell;
public GUIPersonPicker(Shell parent, int style) {
super(parent, style);
}
public GUIPersonPicker(Shell parent) {
this(parent, SWT.NONE);
}
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setLayout(new GridLayout());
shell.setSize(470, 603);
shell.setText("SWT Dialog");
final Label label = new Label(shell, SWT.NONE);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
label.setText("Suchen nach:");
text_1 = new Text(shell, SWT.BORDER);
text_1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
label_1.setText("Suchergebnisse:");
table_1 = new Table(shell, SWT.FULL_SELECTION | SWT.BORDER);
final GridData gridData_2 = new GridData(GridData.FILL_BOTH);
gridData_2.horizontalSpan = 2;
table_1.setLayoutData(gridData_2);
table_1.setLinesVisible(true);
table_1.setHeaderVisible(true);
final TableColumn firstname = new TableColumn(table_1, SWT.NONE);
firstname.setWidth(90);
firstname.setText("Vorname");
final TableColumn surname = new TableColumn(table_1, SWT.NONE);
surname.setWidth(90);
surname.setText("Nachname");
final TableColumn place = new TableColumn(table_1, SWT.NONE);
place.setWidth(90);
place.setText("PLZ - Ort");
final TableColumn street = new TableColumn(table_1, SWT.NONE);
street.setWidth(90);
street.setText("Straße - Nr.");
final TableColumn tableColumn = new TableColumn(table_1, SWT.NONE);
tableColumn.setWidth(90);
tableColumn.setText("New column");
//
}
}
when i use the button the whole application shuts - what is wrong?