Focus issues with JWebBrowser when browser window is refocused - java

I am using DJBrowser in my swing application to show a static html page with style sheets.
The JWebBrowser instance is added inside the panel and the panel is inside JFrame. The issue is with focus not coming back inside the browser when the browser frame regains the focus.
I am using java 6 (jdk 1.6.0_21 to be specific).
I have tried the SimpleWebBrowserExample inside the DJProject. After opening the JWebBrowser, the focus/cursor will go inside the browser content e.g. google search text field. When the screen is de-focused by ALT+TAB and refocused using the same keys, focus does not come inside the text field again (Not sure where the focus is going).
In my application, after opening the html page in the browser user generally wants to find some words inside the page using CTRL+F option then switch between the application and browser often. But after switching to browser user cannot access CTRL+F option as there is no focus on the native browser. (Unless he/she clicks on the browser by mouse).
After reading other similar posts I have tried setting the focus to the native component like - getNativeComponent().requestFocus(), but this did not work.
Could someone please help?

I got the answer to my question above from Christopher Deckers.
If you control the web page, you could keep track of the focused control, and maybe execute Javascript code to restore focus when you detect it should re-acquire it. Javascript code could be something like:
document.getElementById("mytext").focus();
This helped me. Now the web component is getting focus when the window is focused.
Just sharing with you all.
Thanks,
Tushar

Related

What Swing text component can I use to have hyperlinks open in browser?

I have a JEditorPane which has been set uneditable with JEditorPane#setEditable(false) that is set to display HTML that I load from an external source of which I have no control of. Many times there are hyperlinks in the HTML, however while hovering over the link will change the cursor to a interactive image (in widows, changing from pointer to finger), clicking the hyperlink will do nothing.
Is there any swing component I can use that will display text in this sort of manner, but will respond to clicking a hyperlink and open the default web browser?
Detecting the click on the link is relatively easy, as described in the JEditorPane documentation.
Then use Desktop.browse(URI) to show the URL in the default browser.

How can I get rid of the "back" button in my j2me programms while using LWUIT?

I'm writing a j2me application using LWUIT. I make a GUI in the LWUIT Resource Editor. But there's a little problem: when I switch through the Forms in my mobile application, the "back" soft button appears (it's task is to move user to the previous form). It turns out, however, that it's ineptly in my program. So, how can I get rid of it? If possible, how can I do so through a quite comfortable LWUIT Resource Editor (the whole GUI is made in it).
The Form object have a method to capture the default back Command. This method is the following Form API getBackCommand
Use this method to get the back Commandand after that, remove it with the Form.removeCommand(backCommand)
If this doesn't work, take a look in the Commands added in the resource editor. The resource editor always add a back Command when the Form is the navigation of the program

SWT listener for JavaScript window.resizeTo?

I'm working on an application that uses the SWT Browser widget to display an HTML page with some JavaScript in it. The JavaScript tries to use window.resizeTo to change the size of the window, but it currently isn't having any effect.
I've fiddled with the browser settings, and it doesn't seem to be an issue with the underlying browser; switching between Mozilla and Internet Explorer rendering engines has no effect. I suspect that SWT simply doesn't automatically re-size the window in response to JavaScript functions.
I can easily re-size the window from my Java code, but I need to know when to re-size it, and how big JavaScript wants it to be. Does SWT provide a way to listen for this? If so, how?
I still don't know of any way to get this information, but a work-around is to change SWT versions. Some of them implement JavaScript's window.resizeTo automatically, and some of them do not.

GWT refresh cyle in development mode

I am getting a serious problem with gwt. When I am first launching the server, I am viewing the page but later when refreshing the browser, I am getting a blank page. When I do view source, I see all the required tags such nocache.js and history frame but i get a blank screen
According to me, When you refresh the page, you are not on the home page. So you replace panels on onmodulLoad on the home page, but in other pages main panels is not generated and replaced in browser.
To check my theory. Please insert a System.out.println("isLoading"); start point of onModuleLoad. Be sure In initial case "isLoading" written to console. After try to refresh page. It it isn't written you must load your homepage whenever refreshed browser.
I hope, my solution is clear.

How to drag from browser area and deposit to the explorer area?

Sometime ago I was facing the problem the other way around: how to drag an item (folder/file) from an explorer window (be it windows explorer, linux nautilus etc.) to the browser window - that is, the drag starts in one application and ends in the browser. Since I had control over the browser, I was able to intercept the dragend event: the one which interested me.
Now, I want to do this from the browser to the file explorer application: much like when you drag an image from firefox and drop it in a folder.
My main problem is that while I can check when the drag event exited the browser window, I have no ideea how to get the location where the drag event finished.
My ideea is to create a signed java applet and somehow track the mouse movement on the desktop - but this seems a little more than overkill.
Any pointers on this?
According to your justification is is not simple, but it can be managed. There is class called DataFlavor. You had to use D&D mechanism introduce in java using Transferable objects and provide correct mime-types and corresponding conversion. The problem is which mime-type will be accepted by explorer. I hope this help.
You won't be able to do this with JavaScript. JS is sandboxed in the browser and can't interact with anything outside.

Categories