[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] question about key event
|
hi everyone, i have a question about event. there is a shell with a text on
it. i add a keylistener to both the shell and the text. when i type
something in the text, the listener bind to the text is notified, but the
listener bind to the shell is NOT notified. i want the shell's listener is
also notified, what should i do?
thanks in advance!
package test.swt.event;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TestKey1 extends Shell {
private Text text;
/**
* Launch the application
*
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
TestKey1 shell = new TestKey1(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell
*
* @param display
* @param style
*/
public TestKey1(Display display, int style) {
super(display, style);
createContents();
addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent e) {
System.out.println("shell");
}
});
}
/**
* Create contents of the window
*/
protected void createContents() {
setText("SWT Application");
setSize(500, 375);
text = new Text(this, SWT.BORDER);
text.addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent e) {
System.out.println("text");
}
});
text.setBounds(50, 65, 80, 25);
//
}
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}