Menu

#65 The demo ConstrainVisibility.java run error. The JWebBrowser always display at the top layer

v1.0_(example)
open
nobody
None
1
2012-11-25
2012-11-07
ritter
No

Hi,
I try to use JLayeredPane to display a JButton above JWebBrowser,but the JButton always below the JWebBrowser.

And I have found the link:http://stackoverflow.com/questions/6627979/component-overlaping-in-jlayeredpane

which tells to use " new JWebBrowser(JWebBrowser.constrainVisibility());",but I get error below:

on in thread "AWT-EventQueue-0" java.lang.IllegalStateException: The JNA libraries are required to use the visibility constraints!
at chrriis.dj.nativeswing.NativeComponentWrapper.createEmbeddableComponent(NativeComponentWrapper.java:201)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent.createEmbeddableComponent(SWTNativeComponent.java:1164)
at chrriis.dj.nativeswing.swtimpl.components.core.NativeWebBrowser.createEmbeddableComponent(NativeWebBrowser.java:1187)
at chrriis.dj.nativeswing.swtimpl.components.JWebBrowser.(JWebBrowser.java:191)
at chrriis.dj.nativeswing.swtimpl.components.JFlashPlayer.(JFlashPlayer.java:237)

My jna is jna-3.2.4.jar, which comes from the download DJNativeSwing package.

If I run the demo "ConstrainVisibility.java", I get the same error too.

Is there someone knows how to make the JWebBrowser do not show at the top layer ???

Discussion

  • Christopher Deckers

    Hi,

    There are 2 libraries that are needed, both shipped in the distribution:

    • The standard JNA library.
    • The jna_WindowUtils.jar library.

    Are you sure you have both libraries in your classpath?
    -Christopher

     
    • ritter

      ritter - 2012-11-08

      Hi,

      The problem solved with your advice.
      I used to only import one of them. :P
      Thank you so much!!!

       
    • ritter

      ritter - 2012-11-08

      Hi

      When I run the demo "ConstrainVisibility.java" on Ubuntu, the swing button can cover the JWebBrowser successfully, but on Mac, the JWebBrowser still on the top layer, it covers the swing button.

      My environment list below:

      Mac os X:
      10.7.5

      java -version:
      java version "1.6.0_37"
      Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11G63)
      Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

      DJ Native Swing:
      DJNativeSwing-SWT-1-0-2-20120308

      SWT:
      swt-4.2.1-cocoa-macosx-x86_64

      jna:
      jna-3.2.4.jar and jna_WindowUtils.jar

      Please help me, I need it works on Mac.

       
  • Christopher Deckers

    To be honest, I hate Mac because the JRE has lots of unexpected behaviors: things never work as expected.
    This feature would require hiding the native area which is covered by applying a clip composed of a collection of rectangles: this does not work on the Mac.

    In Java 6, there is an API that allows applying a clip to components. I could use that API to apply a non-rectangular clip and achieve the desired effect of overlapping components. Unfortunately, this API is considered not mandatory and was not implemented on Mac. In fact, the new lightweight/heavyweight mixing that Sun implemented in Java 6 uses that internal API and does not work on Mac.
    We would think that maybe this is implemented on Java 7, but unfortunately, Java 7 integration of SWT native components does not work due to limitations in the JRE. They know about it but I don't think they have done any work on it yet.

    Hope this helps,
    -Christopher

     
    • ritter

      ritter - 2012-11-13

      Hi,
      I have found that if I use AWT Button instead of swing JButton, the button can cover the JWebBrowser successfully, but there is still a problem I can't fix:
      What I want to do is to dispaly google map in JWebBrowser, If I set this HTML to browser:

      <html>
          <body>
              <h1>Some header</h1>
      <p>A paragraph with a <a href=\"http://www.google.com\">link</a>.</p>
          </body>
      </html>
      

      and go to the map page, the button can still cover the map, but if I call the google map api directly:

      <!DOCTYPE html>
       <html>
        <head>
        <meta name="viewport" content="initial-scale=1.0,            user-scalable=no" />
        <style type="text/css">
         html { height: 100% }
          body { height: 100%; margin: 0; padding: 0 }
          #map_canvas { height: 100%;
      position: relative;
      z-index: -1;  }
      </style>
       <script type="text/javascript"  
         src="http://maps.googleapis.com/maps/api    /js?key=AIzaSyDX8eJqTwt_CeZg_vhyA-M06bNJrBL4mKw&sensor=true">
        </script>
        <script type="text/javascript">
      var map
      function initialize() {
        var myLatLng = new google.maps.LatLng(32.0, 119.0);
        var mapOptions = {
         zoom: 2,
        center: myLatLng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
       };
      map = new google.maps.Map(document.getElementById("map_canvas"),
      mapOptions);    
      }
        </script>
      </head>
      <body onload="initialize()">
        <div id="map_canvas" style="width:100%; height:100%"></div>
       </body>
      </html>
      

      the AWT Button will be covered by the JWebBrowser.

      I don't know why this happens, Is there some features in google map api lead to this problem? Do you have some idea about how to add a button above the google map which loaded by JWebBrowser?

       

      Last edit: ritter 2012-11-16
  • Christopher Deckers

    Mac mixing is messed up and the AWT and SWT teams are working on it. Until they resolve it we are a bit stuck...

    -Christopher

     

Log in to post a comment.