Quiz software, teaching tools, exam revision aids, learning games, courseware authoring
Java Menus
Java menu homeJava downloadBuy a java menuJava menu help centreContact us
Java menus » Java menu knowledge base

 SEARCH

 MENUS BY TYPE

 Drop-down menus

 Animated buttons

 Tree menus

 Sliding menus

 Tab menus

 Image maps

 MENUS BY NAME

 X-Bar menus

 iPOP menus

 iSlide menus

 iTree menus

 iTab menus

 iMMap menus

 Sensomap menus

 Magic menus

 MENU DESIGN

 Menu design

 Drop-down menus

 Web buttons

 Tree menus

 Sliding menus

 Menu tabs

 Image maps

 SITE LINKS

 Home

 Java downloads

 Prices / Buying

 Support

 Company

 Contact

 New menus

 Free menus

 PARTNER SITES

 Alien Menus

 Happy Menus
Java menu knowledge base
Sizing applets
Return to knowledge base directory

 
Auto-adjusting applet size for screen size
 
Lots of people like to make their applets and other page elements proportional to the size of the site visitor's screen. This is especially important if you are using a topbar applet and you would like the applet to extend the exact width of the screen.
 
Here are some important tips and scripts to help you do this right.
 
  1. Can I use percentage width/heights like I do with HTML elements?
     
    This is not advised as a very few of the hundreds of Microsoft java interpreters have a bug relating to percentage widths and heights. Avoid percentage widths (or heights) for applets if you can.
     
  2. How can I get an applet to size to exactly the screen width?
     
    Use this code:
    <script language="Javascript">
    var w = (navigator.appName=="Netscape") ? innerWidth : document.body.clientWidth;
    document.write("<applet code=myApplet.class width=" + w + " height=25 mayscript>");
    </script>
    
  3. How can I get an applet to size to, say, 15% of the screen width?
     
    Use this code:
    <script language="Javascript">
    var w = (navigator.appName=="Netscape") ? innerWidth : document.body.clientWidth;
    var proportion = 15;
    w = w * proportion / 100;
    document.write("<applet code=myApplet.class width=" + w + " height=25 mayscript>");
    </script>
    
    Change the value of "proportion" to change the percentage width.
     
  4. How can I get the applet to resize with the browser window?
     
    The above scripts won't automatically resize the applet when the browser window is resized by the visitor. The page needs to be refreshed again before the applet will resize. To force the page to refresh, you can put an onResize() method into your <BODY> tag.
     
  5. Anything else I should do?
     
    You should turn off scrolling in the frame which holds the applet. For example, if you are using a top frame to hold an applet navigation bar across the top of the screen, it could ruin the whole effect if a minor browser sizing idiosyncracy resulted in a horizontal scrollbar appearing right across the screen. Be safe and switch off scrolling in the <BODY> tag.
     
  6. So what's the ideal <BODY> tag for an applet page?
     
    <BODY marginheight=0 marginwidth=0 leftmargin=0 topmargin=0 onResize=self.location.reload() scroll=no>
     
    This includes cross-browser code for getting the applet to snuggle exactly into the top left hand corner with no annoying margins. The reload() function is only needed if you are using the resizing scripts. Scrollbars should normally be off. If you'd like a scrolling applet, using those of our applets which have their own scrollbars is much more memory efficient and elegant.
     

 
java menu