Desktops
At this point,
you
might be thinking that there’s nothing more that Swing could
possibly do. But it just keeps getting better. If you’ve ever
wished that you could have
windows within windows in Java, Swing
now makes it possible with JDesktopPane and
JInternalFrame. Figure 15.10
shows how this works.

Figure 15-10. Using internal frames on a JDesktopPane
You get
a lot of behavior for free from
JInternalFrame. Internal frames can be moved by
clicking and dragging the title bar. They can be resized by clicking
and dragging on the window’s borders. Internal frames can be
iconified, which means reducing them to a small icon representation
on the desktop. Internal frames may also be made to fit the entire
size of the desktop (maximized). To you, the programmer, the internal
frame is just a kind of special container. You can put your
application’s data inside an internal frame.
The following brief example shows how to create the windows shown in Figure 15.10.
//file: Desktop.java import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class Desktop { public static void main(String[] args) { // create a JFrame to hold everything JFrame f = new JFrame("Desktop"); f.addWindowListener(new WindowAdapter( ) { public void windowClosing(WindowEvent we) { System.exit(0); } }); f.setSize(300, 300); f.setLocation(200, 200); JDesktopPane desktop ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access