O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required