Focused windows don't lose focus

Having problems with building or using the JCEF Java binding? Ask your questions here.

Focused windows don't lose focus

Postby rivolt80 » Fri Apr 13, 2018 11:57 pm

In the JCEF simple or detailed app that's available by default in the binary_distrib directory, whenever a new dialog/window is launched apart from the main JFrame window, the app starts to behave awkward. Clicking the window that's not in focus doesn't bring it to focus. I have to click multiple (sometimes more than 20) times to get focus there.

I will clarify by mentioning what I'm doing and what's happening. I have the MainFrame class that extends JFrame. The code inside MainFrame is untouched. In the main method, I am creating an instance of MainFrame (named mf) and adding a loadHandler to mf.client so that when the load ends, the application creates a new JDialog with its parent set to mf (because MainFrame extends Jframe, mf itself is an instance of JFrame). This dialog shows the developer toolbar. I am making sure that the dialog is created only once by setting a flag that changes its state when the first dialog is created. I know it's not the best way but I 'm doing it just to keep things simple.

main method:

Code: Select all
public static void main(String[] args) {
        MainFrame mf = new MainFrame("https://stackoverflow.com", OS.isLinux(), false);
        mf.client.addLoadHandler(new CefLoadHandlerAdapter() {
            @Override
            public void onLoadEnd(CefBrowser cefBrowser, CefFrame cefFrame, int i) {
                super.onLoadEnd(cefBrowser, cefFrame, i);
                if (!dialogOpened) {
                    JDialog dialog = new JDialog(mf);
                    dialog.setSize(800, 200);
                    Component devComponent = mf.browser.getDevTools().getUIComponent();
                    dialog.add(devComponent);
                    dialog.setVisible(true);
                    dialogOpened = true;
                }
            }
        });
    }


When I run the app, the devtools dialog pops up when client is done loading as expected. Now if I click the main browser frame to get focus there and change url so I can visit other websites, the dialog popup steals focus immediately. I get focus on the MainFrame after clicking on it here and there multiple times. Once the MainFrame is back in focus, app behaves similar when trying to get focus on the dialog that displays developer toolbar. This weird "race" to get the focus between windows continues throughout the lifespan of the app. I should mention that this is nothing specific to the devloperTools UI component because even if I launch empty dialogs or dialogs obtained by executing JavaScript on the mf.browser (e.g. window.open, alert, prompt etc.) instance.

I built Jcef from source using Visual Studio 2015 in my windows 10 64-bit PC. Currently I'm developing the Cef App in IntellijIdea.
rivolt80
Newbie
 
Posts: 4
Joined: Fri Apr 13, 2018 5:16 am

Re: Focused windows don't lose focus

Postby magreenblatt » Sat Apr 14, 2018 9:21 am

The focus problem on Windows is due to the FocusParent call in Java_org_cef_browser_CefBrowser_1N_N_1SetFocus: https://bitbucket.org/chromiumembedded/ ... N.cpp-1269

You can comment out that call for now to work around the problem.
magreenblatt
Site Admin
 
Posts: 8293
Joined: Fri May 29, 2009 6:57 pm

Re: Focused windows don't lose focus

Postby rivolt80 » Sat Apr 14, 2018 12:48 pm

Awesome! It worked :)
rivolt80
Newbie
 
Posts: 4
Joined: Fri Apr 13, 2018 5:16 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 3 guests

cron