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.