Bug #2548

Updated by Sebastien Jacquot about 1 year ago

There is a conflict between the key events of AWT and SWT using RCP 4.7.3 and Java 1.7, 1.8, 1.10. It seems the bug is present since Java 1.7.
It leads to some bugs related to focus management and Part activation.
Also see: https://www.eclipse.org/lists/albireo-dev/msg00259.html for workaround tests.

It leads to these bugs in TXM:
* Once an AWT component has gained the focus, the AWT Window never loses the focus and seems to capture all key events
=> then every SWT component that should trigger event from keys doesn't work (Text field, Table arrow keys, etc.)
* Specificities selection bar chart => Banality spinner doesn't react to keys if the chart AWT component has gained the focus once
* Progression => Query field doesn't react to keys if the chart AWT component has gained the focus once
* CA, selection of lines in columns and rows tables doesn't work anymore
* Browser Part activation doesn't work

I made this minimal sample example:

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextField;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class SWTAWTFocusBugsSnippet {

public static void main(String[] args) {

final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

Composite composite = new Composite(shell, SWT.EMBEDDED);

Frame frame = SWT_AWT.new_Frame(composite);
Panel panel = new Panel(new BorderLayout());
panel.add(new TextField());

Text text = new Text(shell, SWT.BORDER);


while(!shell.isDisposed()) {
if (!display.readAndDispatch()) {

In this sample, once the AWT TextField has gained the focus, it becomes impossible to type in the SWT Text widget.
It works well on Windows.
Need to check on OS X.

h3. Solution 0/ workaround

* set the AWT frame as non focusable on Linux (and Mac?)
* * it will restore the SWT key events managment
* * it will disable all key event in charts

h3. Solution 1

* stop to use the SWT_AWT bridge
* * use JavaFX bridge
* * use full SWT charts engine but no solution are mature as JFreeChart, especially for interactive charts
* * TBD

h3. Solution 2

* push Oracle/SWT issues so they fix these problems
* check/find information about this issue in Java 11, 12 and most recent Eclipse/SWT versions
* * I didn't manage to test Java 11 in Eclipse 4.7.3