Building a Desktop

In this section, we’ll pull together some of the things we’ve discussed in the previous section to create an application using JDesktopPane , JInternalFrame , and a custom DesktopManager . The example will show:

  • The effect of adding frames to different layers of the desktop

  • How to display a background image (“wallpaper”) on the desktop

  • How to keep frames from being moved outside of the desktop

  • How to deiconify, move, and resize internal frames by frame " tiling”

  • How to take advantage of JInternalFrame’s constrained properties by requiring that there be at least one noniconified frame on the desktop

Figure 9-4 shows what the application looks like when it’s running. Here, we see the desktop with three frames, plus a fourth that has been iconified. The frames titled “Lo” are in a lower layer than the “Up” frames. No matter which frame is active or how the frames are arranged, the “Up” frame always appears on top of the others. Frames in the same layer can be brought to the front of that layer by clicking on the frame. This display also shows the use of a background image (what good is a desktop if you can’t put your favorite image on the background, right?). This image is added to a very low layer (the lowest possible Java int, actually) to ensure that it is always painted behind anything else in the desktop. Figure 9-5 shows the same display after the frames have been “tiled.”

Figure 9-4. SampleDesktop layered frames and background image

Figure 9-5. SampleDesktop with ...

Get Java Swing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.