Skip to Content
Learning Java, 4th Edition
book

Learning Java, 4th Edition

by Patrick Niemeyer, Daniel Leuck
June 2013
Beginner
1007 pages
33h 32m
English
O'Reilly Media, Inc.
Content preview from Learning Java, 4th Edition

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 makes it possible with JDesktopPane and JInternalFrame. Figure 18-10 shows how this appears.

You get a lot of behavior for free from JInternalFrame. Internal frames can be moved by clicking and dragging the titlebar. 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 just as with any other type of container.

Using internal frames on a JDesktopPane

Figure 18-10. Using internal frames on a JDesktopPane

The following brief example shows how to create the windows shown in Figure 18-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) {
        JFrame frame = new JFrame("Desktop");

        JDesktopPane desktop = new JDesktopPane();
        for (int i = 0; i < 5; i++) {
          JInternalFrame internal =
              new JInternalFrame("Frame " + i, true, true, true, true);
          internal.setSize ...
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.
Start your free trial

You might also like

Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan

Publisher Resources

ISBN: 9781449372477Errata PageSupplemental Content