WHITE PAPERS  |  PRICING  |  DOWNLOADS

 

username

password

 

 

 

 

 

 

 

 

 

 

  Desktop Edition Details  

 

  > Features  

  > Key Benefits  

  > Screenshots  

  > Standards Supported  

  > Pricing  

  > Download Now

 

 

  Developer Resources  

 

  > API Documentation  

  > Developers Guide  

  > Code Examples  

  > Updated Builds  

  > Technical Articles  

 

 

 

 

 

Jump to:

General WebRenderer Functions

  WebRenderer example code base.

 

Advanced WebRenderer functions

 

Application test examples

 

Deploying WebRenderer

WebRenderer DOM

  

  

 

WebRenderer JMenus

 

 

 

Using JMenus with WebRenderer  - click here to download complete JMenu example code

 


Java JMenus are particularly useful in creating default context menus for right-click activation.

We have constructed a small example application demonstrating the use of JMenus and WebRenderer. When the menu items are clicked a message will be output to the command line from each menu item.

The core pieces of the code are as follows:

 


             IBrowserCanvas browser = BrowserFactory.spawnMozilla();
            /*
             * Disabling the default context menu right-click menu)
            */
            browser.enableDefaultContextMenu(false);

           JPopupMenu menu = new JPopupMenu("Context Menu");
           JMenuItem menuItem1 = new JMenuItem("Menu Item 1");
           JMenuItem menuItem2 = new JMenuItem("Menu Item 2");
           JMenuItem menuItem3 = new JMenuItem("Menu Item 3");
 
           menu.add(menuItem1);
           menu.add(menuItem2);
           menu.add(menuItem3);
 
           /*
            * Making the menu heavyweight - this prevents the menu going behind
            * the canvas. This is a bug with Swing menus,other Swing components do
            * not have this issue.
           */
           menu.setLightWeightPopupEnabled(false);
 
           //Nesting a MouseListener for the WebRenderer browser
           browser.addMouseListener(new MouseAdapter() {
                       public void onMouseDown(MouseEvent e) {
                                //Check if it is a right click
                                if (e.getModifiers() == 4) {
                                        //If it is a right click then show the menu
                                        
int x = e.getX();
                                        int y = e.getY();
                                        menu.show(browser.getCanvas(), x, y);

                                        menu.repaint();
                                } else {
                                        menu.setVisible(false);
                                }
                        }
                });

Core code
 
Making the PopupMenu a heavyweight component is essential to ensure that the component shows above WebRenderer. setLightWeightPopupEnabled(false) sets the popup menu to heavyweight and has the correct Z-Order.

  top

 

 

 Sun, Sun Microsystems, and the Sun Logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries 

Privacy Policy  |   Disclaimer