first render and LoadURL() seem to break JTextFields? [SOLV]

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

first render and LoadURL() seem to break JTextFields? [SOLV]

Postby johnrdorazio » Sun Nov 01, 2020 6:28 am

I have a JCEF component inside a JInternalFrame inside a JFrame (used in a plugin for OpenOffice written in Java).
There is also a JPanel with a number of components inside the same JFrame.
I'm testing on a Windows 10 machine, so OSR is set to false:
Code: Select all
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = OS.isLinux();


If I set it to true, then the UI of the JFrame becomes completely unresponsive, so I'm leaving it to OS.isLinux().
In this latter case however, some of the components are still not fully responsive, specifically JTextFields.
When opening the JFrame for the first time, the browser takes a couple seconds to initialize, and in the meantime the JTextFields become uneditable.
However, if the Frame loses and regains focus, the JTextFields are again editable.
The same happens every time I call
Code: Select all
browser.loadURL()
: JTextFields become uneditable. If I again lose / gain focus on the Frame they are again editable.

This only happens for the JTextFields, not for other components. They are still focusable, just won't respond to keyboard input.
If I check the editable state on the JTextField after calling "loadURL()" I see that it set to be editable.

Thinking it might be a problem with long running processes blocking the EDT, I thought I would try delegating the loadURL() calls to a SwingWorker. However the problem remains.

See also this stackoverflow post: https://stackoverflow.com/questions/64622736/jtextfield-in-jframe-uneditable-when-using-jcef-in-jinternalframe-until-jframe-l.

I have tried calling, at the end of the SwingWorker's background work:
  • jTextField1.revalidate(); jTextField1.repaint();
  • jTextField1.setEditable(false); jTextField.setEditable(true);
  • jTextField1.updateUI(); //this seems to generate a stacktrace even though I'm not seeing a specific exception?
But to no avail. The only way to get the JTextFields responsive again is to either manually lose focus from the Frame and then gain focus again, or to automatically set the Frame to visible(false) and then to visible(true) using a loadHandler:

Code: Select all
                    client.addLoadHandler(new CefLoadHandlerAdapter() {
                        @Override
                        public void onLoadingStateChange(CefBrowser browser, boolean isLoading,
                                boolean canGoBack, boolean canGoForward) {
                            if (!isLoading) {
                                //browser_ready = true;
                                System.out.println("Browser has finished loading!");
                                SwingUtilities.windowForComponent(browser.getUIComponent()).setVisible(false);
                                SwingUtilities.windowForComponent(browser.getUIComponent()).setVisible(true);
                            }
                        }
                    });
Last edited by johnrdorazio on Sun Nov 01, 2020 7:45 am, edited 1 time in total.
johnrdorazio
Newbie
 
Posts: 5
Joined: Wed Oct 14, 2020 3:04 am

Re: first render and LoadURL() seem to break JTextFields?

Postby johnrdorazio » Sun Nov 01, 2020 7:44 am

I figured out the problem. Studying the sample application a little better, I see that I need to implement a focus handler for the text fields, to make the browser relinquish it's hold on the keyboard:
Code: Select all
        jTextField1.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                if (!browserFocus_) return;
                browserFocus_ = false;
                KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
                jTextField1.requestFocus();
            }
        });
johnrdorazio
Newbie
 
Posts: 5
Joined: Wed Oct 14, 2020 3:04 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 2 guests