Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353683 - JRE7 Issues with SWT_AWT bridge Focus issues particular with browser
Summary: JRE7 Issues with SWT_AWT bridge Focus issues particular with browser
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.1   Edit
Hardware: PC Windows 7
: P3 normal with 28 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-02 17:41 EDT by Eduardo CLA
Modified: 2020-08-11 02:50 EDT (History)
19 users (show)

See Also:


Attachments
a snippet that add a browser into Swing Jframe and the issue can be reproduced (7.51 KB, application/x-zip-compressed)
2011-08-02 17:48 EDT, Eduardo CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eduardo CLA 2011-08-02 17:41:51 EDT
Build Identifier: SWT 3.7

the issue only happends when using the JVM version 7(1.7.0) using JVM 6(1.6.0_25) works fine. (so Far I have seen this issue on Windows 7 with IE8 browser)
I have a Jframe Swing component, and i add a SWT_AWT component into a AWT canvas (a shell that contains a browser object)
 now this frame has others components such as panels buttons, text areas and so on... 
now the problem is when i use the web browser and type something into the webbrowser and then I try to focus the External(Swing) component the Keyboard focus remains on the Webbrowser(note the Swing component triggers a Focus Gain event and A carret is show) and does not allow me to type anything on the Swings components Unless I extract the focus to a diferent window that the affected application
also i have experince the issue on the DJ native project that also add SWT components into Swing.
http://djproject.sourceforge.net/ns/

Reproducible: Always

Steps to Reproduce:
1.create a SWT_AWT shell with a webbrowser(IE8/win 7 in the cases i have tested so far)
2.navigate to any textfield and set keyboard focus
3.try to set focus on a Swing component outside the webrowser
Comment 1 Eduardo CLA 2011-08-02 17:48:23 EDT
Created attachment 200764 [details]
a snippet that add a browser into Swing Jframe and the issue can be reproduced

on the attached I have a Source of an application using SWT witha JVM version 7 the issue can be reproduced.
as this example try to access google. 
type something on the google text area, and try to go back to the JtextArea it will not allow to type.
Comment 2 Eduardo CLA 2011-08-30 11:59:58 EDT
Any Update On this issue?
Comment 3 Eduardo CLA 2011-08-31 18:22:43 EDT
We noticed The Swing Components regains focus if we show a Dialog(such a JOptionPane) then close it

also if the browser is on a TabPanel inside a JTabbedPane Component and we create a new tab it also returns the focus back to swing. however removing Tabs will not provide the same effect... unless of course the tab where the browser is located is closed. 

another aspect that we are able to return focus back to swing is removing focus completely from the java application and select another application then select the application back, when the OS provides focus is provided to the Swing Application and SWT release it.
Comment 4 Christopher Deckers CLA 2011-09-17 04:04:47 EDT
I too had bug reports about this incompatibility with Java 7.

I found a hack to allow Swing to regain focus:
- I attach a global AWT listner.
- On mouse pressed or focus gain, I disable and re-enable all embedded shells.
-> this forces the native components to release focus.

 It solves most cases though it is easy to have a visual incoherence in the form of 2 carets: one in the Browser (the focused component), and one in Swing's text field which thinks it has the focus.

This is a hack and I hope it is a temporary solution to this problem...

One thing to consider is that there was significant work from the AWT team to improve lightweight/heavyweight components mixing, and they may have broken something.

Maybe the SWT developers could confirm whether the bug is theirs or if it should be transfered to the AWT developers.
Comment 5 Terry Hau CLA 2011-10-07 05:25:49 EDT
I'm having this same problem with LWJGL.
Create a canvas parent it to LWJGL's OpenGL renderer.
After clicking in the canvas, it starts grabbing keyboard input, and never releases. I try to focus any swing component eg. textbox, and can not type. Hotkeys also don't work.
Comment 6 Nick Vanderhoven CLA 2012-09-18 11:09:56 EDT
I have the same issue, but I can't resolve it by disabling the AWT components and then reenabling them. I have no clue on where to search to find a workaround any more. 

Does the AWT/Swing team knows about this? Any update on this one?
Comment 7 Sikandar Ali CLA 2012-12-25 06:52:14 EST
I have the same issue while developing Eclipse plugin with Swing componenets, try to use the below code to fix it:
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
	IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
	if (window != null) {
	       IWorkbenchPage page = window.getActivePage();
	       if (page != null) {
		    try {
			page.showView("yourViewID...");
		    } catch (PartInitException e) {
			e.printStackTrace();
		    }
	        }
	}
}
Comment 8 Philippe Destrumel CLA 2013-09-03 12:22:08 EDT
Hi,

We integrate Flash in our Swing application (E-anim, free software) and these focus issues render our program unusable. Thus, this is a particularily critical issue for us.
Feel free to contact me/us if you need any information about our Flash integration

Philippe Destrumel
Comment 9 Henno Vermeulen CLA 2014-02-07 10:09:36 EST
With 4.3.1 (but not 3.7) I am getting an NPE at the same location. I have a PartListener2Adapter with a partClosed method that tries to reopen the editor that is being closed. (I.e. open a new editor with new but equal editor input).

Workaround is to use Display.asyncExec.
Comment 10 Henno Vermeulen CLA 2014-02-10 03:51:15 EST
Ignore my previous comment, that was about another ticket!

With Java 7 I'm also seeing a focus issue with the SWT_AWT bridge. (I'm not sure if it's the same but it sounds similar.)

I embed Swing components in a Composite through Albireo's SwingControl which is based on the SWT_AWT bridge. When the composite does not have focus and I click somewhere inside the Swing component, the Composite does not gain focus.

For me this introduces serious bugs. I am using the Composite inside an Eclipse View which provides selection to the workbench, but this selection does not become the active selection because of this focus issue.
Comment 11 Henno Vermeulen CLA 2014-02-10 04:13:19 EST
Perhaps it's better to say that the workbench part containing the SwingControl is not activated by clicking somewhere inside the SwingControl. I'm not sure how this exactly works with focus gained events.
Comment 12 Henno Vermeulen CLA 2014-02-10 04:33:20 EST
What I am experiencing was already reported as https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104
May be related to this bug, my apologies if it is not.
Comment 13 Alessandro D\\\'Ottavio CLA 2016-10-14 06:42:20 EDT
I know that the post is old... 
but also with newer version it doesn't work

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) Client VM (build 25.102-b14, mixed mode, sharing)

<dependency>
	<groupId>org.eclipse.swt</groupId>
	<artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
	<version>4.3</version>
</dependency>
Comment 14 Eclipse Genie CLA 2020-08-11 02:50:45 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.