Issue with Browser and TraverseListener [message #498673] |
Tue, 17 November 2009 19:58  |
Eclipse User |
|
|
|
Hi everyone,
I'm programming a nice little html tooltip type window of which you should be able to close by the click of the escape button and came upon this issue.
From what I can tell, the browser control eats all the traverse events (tab, escape) and never passes it to a following traverse listener. An example of this is the code provided below. First click on the Text composite and press escape, you will notice the window closes. Then open it and click on the browser so it has focus and press escape. You will notice it wont close.
public static void main(String [] args) {
Display display = new Display();
final Shell shell = new Shell(display);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
shell.setLayout(gridLayout);
GridData data = new GridData();
data.horizontalSpan = 1;
final Text label = new Text (shell, SWT.NONE);
label.setText("Click here and press escape");
data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.horizontalSpan = 1;
data.grabExcessHorizontalSpace = true;
label.setLayoutData(data);
final Browser browser;
try {
browser = new Browser(shell, SWT.NONE);
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " + e.getMessage());
display.dispose();
return;
}
data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 1;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
browser.setLayoutData(data);
TraverseListener t = new TraverseListener () {
@Override
public void keyTraversed (TraverseEvent e)
{
System.out.println(e.detail);
if (e.detail == SWT.TRAVERSE_ESCAPE)
{
shell.close();
}
}
};
shell.addTraverseListener(t);
browser.addTraverseListener(t);
label.addTraverseListener(t);
shell.open();
browser.setUrl("http://eclipse.org");
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02909 seconds