Can a Java applet write information to the status bar of a browser?

Question: Can a Java applet write information to the status bar of a browser?

Yes, Java applets can write to the status bar of a browser.

(If you're not familiar with the terminology, the status bar is the bar located at the bottom of your browser. It's also called a status line or status window.)

However, consider yourself warned that the status bar is configurable in many browsers, so it's possible that the user can hide the status bar -- and never see the message you're writing. In practice, though, it seems that most users leave the status bar alone, so it's usually worth the small extra effort to write to the bar. In fact, it's so easy to do this in your Java applets that I recommend it.

(If your status bar is currently open and your browser supports JavaScript, you'll see the title of this article displayed there.)

Here's all the Java code you need in an applet to write to a browser's status bar:

// How to write to the status bar of a web browser
// using Java:

showStatus("Hello, world!");

Just use the showStatus() method in your applet any time you want to write to the status bar. An example of this can be found in our AnimatedAd applet. In this applet, we write a brief message to the status bar each time a user moves their mouse over the applet, and the message "sticks" to the mouse pointer.

You'll find the showStatus() method documented in the java.applet.Applet class documentation.

Bonus: Would you like to achieve the same result with JavaScript? Here's the code we use in this page to write the title to your browser's status line:

<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
   window.defaultStatus = 
          "Can a Java applet write to the status bar of a browser?"
//-->
</SCRIPT>
</head>

As you can see, you just need to put this JavaScript code in the <HEAD></HEAD> tags of your HTML code, and change the string to provide the description you'd like.


devdaily logo