WHITE PAPERS  |  PRICING  |  DOWNLOADS

 

username

password

 

 

 

 

 

 

 

 

 

 

  Swing 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

 


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);
 
           //Nesting a MouseListener for the WebRenderer browser
           browser.addMouseListener(new MouseAdapter() {
                       public void onMouseDown(MouseEvent e) {
                                //Check if it is a right click
                                if (SwingUtilities.isRightMouseButton()) {
                                        //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);
                                }
                        }
                });

  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