[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: question about key event

Hi,

Events like this do not automatically propogate up the widget hierarchy, so
if you really want your Shell to send a KeyDown in this scenario then your
Text's KeyDown listener should re-send the received event with
getShell().notifyListeners(Event).

Grant


"Shuai Yang" <yangshuai@xxxxxxxxx> wrote in message
news:g2gu08$7le$1@xxxxxxxxxxxxxxxxxxxx
> 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
>  }
>
> }
>
>