-
Basics
Hi, I'm new here :)
first of all, can anyone point me to a specific code examples about Listeners and Shells?
Now three questions:
1. How do I open a shell inside a shell? i.e, I have the main shell in display and now wanting to open a Message-Box-like shell, that will contain a Text to get some string...
So, I understand the creation, yet I can't find what to write as the part that makes the shell listen constantly. Meaning, what will I do that is similar to:
Code:
shell.open();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in the event queue
display.sleep();
}
}
display.dispose();
(The problem is of course that I DON'T have the "display" object, 'cause the parent here is the main shell...
2. My main shell is defined where the main function is, yet I would like to pop a MessageBox somewhere else. How can I do it when I need to know what shell am I in?
3. Assuming layoutData is of shell is defined as GridData, what determines whether information will be shown by rows or by coloumns?
Thanks in advance,
Avishay
-
Code tags added to make posted code retain its formatting and be more readable.
-
Hi,
use your shell as parent for your Messagebox.
Example code is,
Code:
public class SWTApp {
public SWTApp(Display display) {
final Shell shell = new Shell(display);
shell.setText("Center");
shell.setSize(250, 200);
shell.open();
shell.setMinimumSize(100, 100);
Button button=new Button(shell,SWT.PUSH);
button.setBounds(100, 100, 300, 150);
button.setText("Click Me");
button.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent arg0) {
}
public void widgetSelected(SelectionEvent arg0) {
MessageBox mb=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
mb.setMessage("Hello welcome");
mb.setText("Hi");
mb.open();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public static void main(String[] args) {
Display display = new Display();
new SWTApp(display);
display.dispose();
}
}