Bug #2548
Linux, focus bugs and conflict between the key events of AWT and SWT
Status: | New | Start date: | 04/11/2019 | ||
---|---|---|---|---|---|
Priority: | High | Due date: | |||
Assignee: | - | % Done: | 50% |
||
Category: | Charts | Spent time: | - | ||
Target version: | TXM X.X |
Description
There is a conflict between the key events of AWT and SWT using RCP 4.7.3 or RCP 2019-03 (4.11) 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.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855
https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104
https://bugs.eclipse.org/bugs/show_bug.cgi?id=353683
Also see: https://www.eclipse.org/lists/albireo-dev/msg00259.html for workaround tests.
Help asking: https://www.eclipse.org/forums/index.php/t/1098632/
- 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
- TBD
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()); frame.add(panel); panel.add(new TextField()); Text text = new Text(shell, SWT.BORDER); shell.setSize(200,70); shell.open(); while(!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }
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.
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
- it will disable tooltips of chart entities
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
- try to use JavaFX bridge that embeds the AWT components
- TBD
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
Related issues
History
#1 Updated by Sebastien Jacquot about 4 years ago
- Subject changed from CA, Linux, selection of lines in columns and rows tables doesn't work anymore to Linux, focus bugs and conflict between the key events of AWT and SWT
- Description updated (diff)
- Category changed from UI / Editor to Charts
#2 Updated by Sebastien Jacquot about 4 years ago
- Description updated (diff)
#3 Updated by Sebastien Jacquot about 4 years ago
- Description updated (diff)
#4 Updated by Sebastien Jacquot about 4 years ago
- Description updated (diff)
#5 Updated by Sebastien Jacquot about 4 years ago
- Description updated (diff)
#6 Updated by Sebastien Jacquot about 4 years ago
- % Done changed from 0 to 50
A Linux workaround that seems acceptable has been implemented in /org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java
- an AWT mouse listener on the AWT/Swing chart component calls Frame.setVisible(false) and Frame.setVisible(true) when the mouse exits the component. It frees the key event listener and the Frame focus but the SWT application becomes "not active/gray on Ubunutu/moved to back"
- so SwingChartComposite.this.chartEditor.getShell().forceActive() is called just after the Faame.setVisible(true) to reactivate the SWT part
- it leads to a little flickering of the whole SWT Window that may not be visible on actual machines
- since the chart component is created only when a chart is created, a similar listener does the same process on the embedded frame root panel to manage the result editors that can be empty/have no chart eg. Progression
#7 Updated by Sebastien Jacquot about 3 years ago
- Target version changed from TXM 0.8.2 to TXM X.X