Browser overlaps other swing Components

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

Browser overlaps other swing Components

Postby Ludy » Tue Nov 29, 2016 5:26 am

Hey guys,

I want to use a jcef Browser in a JavaSwing GUI. I have a JDialog, JDesktopPane and some JInternalFrames. In one of the JInternalFrame is my browers. The Problem is when I maximize another JInternalFrame and the content of the Browser is overlapping the maximized Frame.
Does someone know how to solve this?

I'm using JDK 1.8 and the newest jcef version
Ludy
Techie
 
Posts: 12
Joined: Thu Nov 10, 2016 4:48 am

Re: Browser overlaps other swing Components

Postby Ludy » Tue Dec 06, 2016 5:36 am

Does nobody have an idea?
I added a picture how it looks like. The "qwe" frame is maximized and i can still use the browser.

That is my example code. The SimpleFrame is just the example Browser and I returned it in a JPanel.
Code: Select all
   public static void main(String[] args) throws InterruptedException {
      SimpleFrame simple = new SimpleFrame("http://www.google.com", OS.isLinux(), false);
      JDialog c = new JDialog();
      JDesktopPane deskPane = new JDesktopPane();
      JInternalFrame intern = new JInternalFrame("asd", true, true, true);
      JInternalFrame intern2 = new JInternalFrame("qwe", true, true, true);
      intern.add(simple.getBrowser());
      intern.setSize(300, 300);
      intern2.setSize(300, 300);
      intern.show();
      intern2.show();
      deskPane.add(intern);
      deskPane.add(intern2);
      c.add(deskPane);
      c.setSize(500, 550);
      c.setVisible(true);
      c.addWindowListener(new WindowListener() {

         @Override
         public void windowOpened(WindowEvent e) {
            // TODO Auto-generated method stub
         }

         @Override
         public void windowIconified(WindowEvent e) {
            // TODO Auto-generated method stub
         }

         @Override
         public void windowDeiconified(WindowEvent e) {
            // TODO Auto-generated method stub
         }

         @Override
         public void windowDeactivated(WindowEvent e) {
            // TODO Auto-generated method stub
         }

         @Override
         public void windowClosing(WindowEvent e) {
            // TODO Auto-generated method stub
            CefApp.getInstance().dispose();
            c.dispose();
         }

         @Override
         public void windowClosed(WindowEvent e) {
            // TODO Auto-generated method stub
         }

         @Override
         public void windowActivated(WindowEvent e) {
            // TODO Auto-generated method stub
         }
      });
   }
Attachments
JinternalFrame.png
JinternalFrame.png (12.97 KiB) Viewed 17316 times
Ludy
Techie
 
Posts: 12
Joined: Thu Nov 10, 2016 4:48 am

Re: Browser overlaps other swing Components

Postby Phylanx » Wed Dec 28, 2016 2:22 am

Hi!

This sounds like the good old heavyweight vs. lightweight topic.
See http://www.oracle.com/technetwork/artic ... 33992.html

Short informations:
Java Swing uses windows components to use its place on the screen to draw its jcomponents on it (JComponents are "lightweight" components).
So if you see JButtons it is actually only a picture of a button drawn.
If you click it it is drawn as if it looks like when you click a button.

Java AWT Components are heavyweight. They are real native OS components, for example real windows buttons created by windows.
If one of these components is placed on your Window/Dialog/Panel/..., it will overpaint every lightweight component.

For JCEF now it happens that it uses a java.awt.Canvas (heavyweight) internally to give it to the native code to paint the browsers content on it.
so the one JInternalWindow containing this Canvas overpaints everything else being "heavier" than a lightweight.

For more informations and how to fix it, see the link above.

Hope that I could help you with it.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Browser overlaps other swing Components

Postby Ludy » Wed Jan 11, 2017 7:11 am

Thanks for you help.
I'm working with Java 8 and the problems between the heavyweight and lightweight should be fixed, as it is described in the link. I tried it with an awt.Button and a JButton and it is working as expected, but I wonder why it is not working with the browser.

In the link you posted are some cases described which need a workaround or are not working. There is one case which fits for my problem:

The component hierarchy must be validated whenever it becomes invalid. If any part of the hierarchy is invalid, the mixing will not operate correctly....


I tried to fix this with a HierarchyListener and validate my swing component every time the hierarchy become invalid.

Do you know, what I could have wrong?
Ludy
Techie
 
Posts: 12
Joined: Thu Nov 10, 2016 4:48 am

Re: Browser overlaps other swing Components

Postby Phylanx » Wed Jan 11, 2017 8:42 am

There are still heavy/lightweight problems in JDK8, we had the problem with JMenuBars and other Popups (like context menus).
Our problems could be fixed with following calls when starting the application:

Code: Select all
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);
            ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);


We don't use such multiple frames, so we don't have exactly this problem, I could only suggest that this might be the problem.

// edit:
this needs to happen before initialization of the elements, because these flags are needed on component initialization, not when drawn.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Browser overlaps other swing Components

Postby Ludy » Thu Jan 12, 2017 7:08 am

The Component in the "qwe"-frame dont has a .setDefaultLightWeightPopupEnabled(false) function or a similar function, so I have to search for another solution.

I tested the Browsercomponent with isLigthWeight() and I it returned true. I expected false, could the problem be something else than heavy and lightweight components?
Ludy
Techie
 
Posts: 12
Joined: Thu Nov 10, 2016 4:48 am

Re: Browser overlaps other swing Components

Postby Phylanx » Thu Jan 12, 2017 8:53 am

I hope we only speak about non OSR mode and Windows, because I know only that case.

If you ask the CefBrowser for its Component, you'll get a JPanel, that's swing and therefore a lightweight.
But if you have a look in the implementation itself (CefBrowserWr), the Component delivered to native for drawing the HTML is a java.awt.Canvas (field canvas_, which is heavyweight).

How to fix the heavyWeight/lightWeight thing with your frames, I don't know. We didn't have that problem.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Browser overlaps other swing Components

Postby Ludy » Mon Jan 16, 2017 4:27 am

I hope we only speak about non OSR mode and Windows, because I know only that case.


yes I run it with non OSR mode and on Windows.

I tried another test case with a JInternalFrame. I made for one frame a simple Canvas element and for another Frame a JButton and it is shown correctly
Ludy
Techie
 
Posts: 12
Joined: Thu Nov 10, 2016 4:48 am

Re: Browser overlaps other swing Components

Postby Kremio » Thu Apr 20, 2017 4:27 am

Hi!
I realise this is a bit of an old topic but I was curious to know if a solution had been found.

I'm facing the same issue when using a JLayer to overlay and decorate the browser component.
I also tried using a custome glasspane component set to the JFrame that contains the browser component, but the result is the same.

Cheers!
Kremio
Newbie
 
Posts: 5
Joined: Thu Apr 20, 2017 4:23 am

Re: Browser overlaps other swing Components

Postby waicool20 » Sat Apr 29, 2017 12:34 am

Kremio wrote:Hi!
I realise this is a bit of an old topic but I was curious to know if a solution had been found.

I'm facing the same issue when using a JLayer to overlay and decorate the browser component.
I also tried using a custome glasspane component set to the JFrame that contains the browser component, but the result is the same.

Cheers!


It's possible to create an overlay if you use a JLayeredPane in conjunction with a GLCanvas another heavyweight component. I tried this with Canvas, despite being heavyweight doesn't seem to work, JCEF internally uses GLCanvas, so I thought if Canvas isn't heavyweight enough then, GLCanvas should at least be the same weight. Just place the GLCanvas on a layer that's above the uiComponent of the browser in the JLayered Pane and it should render just fine, however transparency is not really possible unless you are able to capture the subimage of the uiComponent that your overlay is covering and draw that first, which I did over here(in kotlin) using a modified version of jcef: https://github.com/waicool20/SikuliCef/blob/master/src/main/kotlin/com/waicool20/sikulicef/graphical/CefOverlay.kt
waicool20
Newbie
 
Posts: 7
Joined: Sat Apr 22, 2017 3:40 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 23 guests