Contents
The final release of the Java Platform, Standard Edition 6 (Java SE 6) has added or updated several features for the Java desktop developer. Note that although previous articles, tech tips, or blog entries have discussed these changes, this article covers the basics from each resource and updates the content to include any changes in the final version of Java SE 6. From the article "New Splash-Screen Functionality in Java SE 6" by Oleg Semenov and Dana Nourie Splash screens are a standard part of any modern graphical user interface (GUI) application. Before Java SE 6, you could use Swing or Abstract Window Toolkit (AWT) to create splash screens in Java technology applications. However, before the splash screen can pop up, the application has to load and initialize the Java Virtual Machine (JVM)*, AWT, usually Swing, and perhaps some application-dependent libraries. The resulting delay of several seconds has made use of a Java technology-based splash screen less than desirable. Java SE 6 provides a solution that allows the application to show the splash screen much earlier, even before the virtual machine starts. Now, a Java application launcher is able to decode an image and display it in a simple nondecorated window, as Figure 1 shows.
There are two ways to show the native splash screen:
In certain cases, you might want to dynamically update the splash
screen while it is being displayed. The The following code sample demonstrates the typical process for creating a splash screen.
First, you obtain the You may change the image in the splash screen with the
The following application is an example of how the new splash screen works.
Note that From the article "New System Tray Functionality in Java SE 6" by Robert Eckstein Java SE 6 lets you access the system tray in Java technology with
the help of two separate classes in the The system tray is a specialized area, typically at the bottom of the desktop, where users can access continually running programs. On Microsoft Windows and the Gnome desktop, the system tray is often referred to as the notification area. On KDE, it is referred to as the system tray. On each system, all applications running on the desktop share this tray area. Figures 2 and 3 show the system tray on both Windows and Gnome. In both cases, the system tray resides by default in the lower right corner of the screen.
The Every Java application has a single The The following code sample demonstrates how to access and customize the system tray:
Compiled from the blog entries "Swing Painting Improvements: No More Gray Rect!" by Scott Violet and "Swing Update: No More Gray Rect" by Chet Haase In scoping out various performance-related projects for JDK 6, the Swing team wanted to tackle one of Swing's long-standing problem areas that has contributed to bad perceived performance. This is called the gray rect problem. That is, when a Swing-based application is exposed after being hidden by another application, there is a noticeable delay between when the background of the window is erased and when the actual contents are painted. With JDK 6, this problem has been fixed. The fix involves adding true double-buffering support to Swing. That is, each application window now has an offscreen duplicate image, known as a back buffer, that is kept synchronized with the onscreen window. When a window is exposed, Swing simply copies directly from the offscreen image, on the toolkit thread, to the screen. An added bonus of this fix is that if your application is blocking the event dispatch thread -- perhaps you're contacting a server, and a user hides your window and then exposes it -- the application will still repaint itself. Swing's original buffering mechanism was created in a time when system memory was a constrained resource, so sharing this back buffer with all Swing windows was important. Instead of a buffer that acts as a backup for the contents on the screen, as back buffers typically do, the Swing buffer acted more as a "scratch buffer" for any pending operations. Whenever an update needed to occur on the Swing window, Swing would render that region into the upper left area of the back buffer and then copy that region into the proper location in the window. The end result was that the contents in the back buffer were not persistent, nor did they typically reflect the contents in the Swing window. For example, if another window was dragged across the Swing window and caused that window to be updated, then Swing would have to repaint that entire area again, because it didn't know what used to be there. With this new approach, Swing now has a separate buffer for each Swing window on the screen, and those buffers' contents are kept synchronized with the graphics in the actual window. So now, if you drag a window across the Swing application window, Swing can simply copy from the back buffer to the screen and save all the work of erasing and then repainting that area. What's more, Swing does this fast-copy operation on the native event thread, which means that there is an immediate response. Figure 4 shows the relative speeds of NetBeans IDE window validations with different JDK releases.
From the blog entry "Phil's Font Fixes" by Chet Haase and Phil Race One of the most frequently requested features has been for JDK 6 to support subpixel text. This is an optimization for LCD displays that uses subpixel striping to increase the text resolution. Because of the way users apply and configure it, subpixel text is often considered a form of text antialiasing. The good news is that JDK 6 implements this feature. Whether you use the look and feel of Metal, Microsoft Windows, or GTK, you will get the same antialiasing behavior for fonts in Java technology-based applications as you do in native applications. Best of all, you don't have to do anything -- it just works out of the box. In order to achieve this, the look and feel of Windows and of GTK have also been updated to track the user's desktop preferences and update any preference changes in real time. Also, the default Java technology look and feel, Metal, now reads the user's desktop text-antialiasing preferences on startup and applies them to the JDK fonts. When used together with the Metal "Ocean" theme, which uses plain fonts instead of bold, the result is quite pleasing to the eye, as shown in Figure 5.
Swing supports five new values for
The first four correspond to the four possible LCD-subpixel configurations. Native GTK applications support all four of these. On Windows, you will need at least XP to get LCD text support in native applications, although Microsoft only supports HRGB on Windows XP, and the company added HBGR in XP Service Pack 1 (SP1). The JDK supports LCD text on all Windows versions. The JDK uses the final hint value, To demonstrate this, look at the JTable demo tab from the SwingSet2 demo. Figure 6 shows it without LCD text.
Figure 7 shows it with LCD text.
The screen capture in Figure 8 shows the same fonts and text as they are rendered with Windows WordPad on the left and with a small JDK application on the right. The fonts used here are ones that users typically see in Windows applications.
Figure 9 is a screen capture that compares some of the more common fonts seen in Gnome applications on Linux alongside the JDK rendering of these fonts. The Gnome text was rendered on Fedora Core in the gedit application. Because gedit can use only one font at a time, several screens of text were captured and stitched together using the GNU Image Manipulation Program (GIMP).
A few notes:
Compiled from the blog entries "STR-Crazy: Improving the OpenGL-based Java 2D Pipeline" and "STR-Crazier: Performance Improvements in JDK 6" by Chris Campbell Until now, Java 2D rendered its graphics on arbitrary Java threads. With single-threaded rendering (STR), requests are now queued at the Java platform level, then executed at the native operating system (OS) level on a single thread. However, this feature is not as visible as many others in JDK 6. At present, STR is implemented only in the OpenGL rendering pipeline, which is not enabled by default due to various driver and hardware issues. Besides being extremely useful from a graphics-software perspective, STR offers significant improvements both for the current OpenGL pipeline and for future rendering pipelines that will use this approach. OpenGL rendering offers benefits both in robustness, as multithreaded rendering in OpenGL tends to cause problems for many video cards, and in performance, as the batching of rendering requests saves significantly in overhead in both the Java Native Interface (JNI) and the OpenGL API. Future Java SE releases will likely use the STR approach in other rendering pipelines, such as the default DirectX renderer on Windows, and provide similar benefits. As most developers are already aware, JDK 5.0 included an OpenGL-based Java 2D pipeline to improve rendering performance. Although the OGL pipeline was a big step forward for rendering performance of complex operations such as transforms, compositing, and gradients, it was not nearly as robust as the existing X11- and DirectX-based pipelines. This meant that users evaluating their Java technology-based applications with the OGL pipeline enabled would see frequent crashes and rendering artifacts. What was causing these crashes? If you're familiar with OpenGL, you probably know that it's important to do all your rendering from a single thread. Although it is possible to render from other threads, OpenGL drivers are optimized for the single-threaded case. Developers are not quite as lucky in Java 2D. Rendering requests can come from any number of threads, including the event-dispatching thread or a user thread. In JDK 5.0, the Java platform dealt with this by taking precautions such as these:
This makes OpenGL drivers reasonably functional, but it requires more labor from the Java technology, which means reduced performance. And despite all efforts, drivers can still crash when there are many rendering threads in use by an application. Clearly, something needed to be done if the OGL pipeline was ever to become reliable enough for day-to-day use by end users. For the past couple of years, several people on the Swing team have discussed the idea of single-threaded rendering, which would allow the Java libraries to interact with native graphics libraries, such as OpenGL, from a single thread. The idea originally came up as a possible solution to a number of threading problems that the Swing team had dealt with in the past on the Windows side. But what better way to test these ideas than to implement them using the OGL pipeline? So that's what the team set out to do in JDK 6. Instead of the scenario in Figure 10, in which multiple threads touch the native graphics layer, a more elegant solution appears in Figure 11.
Here are some quick numbers from a test Linux configuration (JDS, 2x 2.6GHz P4, Nvidia GeForce FX 5600). The numbers look similar on the Solaris Operating System and on Windows:
In JDK 6, the Swing team also set out to reduce the overhead of
small rendering operations, where small refers to operations
in which only a few pixels are touched -- for example a 10x10
pixel Many of the overhead reductions came with the following bug fixes:
With those fixes integrated in JDK 6, it's a good time to step back and chart how much progress the Swing team has made. Figure 12 shows the chart.
Here are the big takeaways:
Even with these improvements, the X11 pipeline still beats the pants off the OGL pipeline in a few operations, due to some highly optimized loops in the Xserver -- for example, small filled ovals. The Swing team will continue to address the most important cases, so ideally the OGL pipeline will close that performance gap. From the blog entry "Hi-Fi Swing (Or Improving the Native Fidelity of Swing System L&Fs)" by Bino George One of Swing's biggest strengths is its lack of a rigid coupling between the underlying platform toolkit and the Swing API. The Swing API was designed to be extensible and free from platform limitations. However, the freedom from platform restrictions comes at some cost in terms of engineering the Swing toolkit. Swing engineers have to make conscious trade-offs between native fidelity and platform independence. Over the years, users have requested that the Swing team provide the absolute best fidelity for system look-and-feel user interfaces. Theming the Windows desktop has been popular for many years. For example, PC manufacturers such as Sony or Gateway have shipped custom Windows themes that provide a branded look that identifies the desktop with the system manufacturer. In addition, many users like the power and flexibility of customizing the desktop. One of the most popular theming applications for Windows is WindowBlinds. In fact, WindowBlinds was so popular that Microsoft worked with the product's author to develop a new API that exposes the rendering of Windows controls: the UxTheme API. Windows XP provides a new default XP look and feel, based on UxTheme, that users can extend using the UxTheme API. In JDK 5.0, the Swing team provided support for the Windows XP look and feel. The mechanism used to provide this support was based on reading the resources embedded in the XP Styles files and using those icons and colors to render the Windows look and feel. Unfortunately, Microsoft has changed the Styles files in Windows Vista so that the resources are no longer visible using the mechanism in JDK 5.0. So naturally when the developers ran the current JDK under Windows Vista, their applications fell back to the Windows classic look and feel used in Windows 2000. Swing will always fall back to this look and feel if it is unable to load the XP look and feel. After some discussions between engineers from the Swing team and from Microsoft's graphics team, the Microsoft team suggested that the way to work with the Windows Vista themes was to use the UxTheme API. So a few Swing-Windows look-and-feel authors prototyped a version of the Windows XP look and feel that uses the UxTheme engine to perform the rendering of Swing components. The authors then tested the prototype under Windows Vista and found that the rendering of the Vista theme was pixel perfect with UxTheme. This lead us to the re-implementation of the Windows look and feel using UxTheme, and this new implementation is available in JDK 6. Part 2 of this article will discuss additional new and updated features in Java SE 6: table sorting and filtering, improvements to the Image I/O library, the new modality model, and the desktop API. _______ For More Information
Overall:
Splash Screens
System Tray
Look and Feel
Java Platform
|
| |||||||||||||||||||||||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||