Frames

  • Probably the most common object used in Swing
  • Cannot use add() to add elements must use getContentPane().add(..)

JDesktopPane

  • Extension of JLayeredPane.
  • Manages JInternalFrames

JInternalFrames

  • A Container that looks like a Frame.
  • Can be iconified (minimised)
//MiniEdit.java

public class MiniEdit extends JFrame {
  private DesktopManager manager;
  private JDesktopPane desktop;
  private MiniToolBar toolbar;
  private MiniEdit theApp;
  private MiniActions actions;

  public MiniEdit() {
    toolbar = new MiniTooBar(this);
    action = new MiniActions(this);

    desktop = new JDesktopPane();
    getContentPane().add(desktop, "Center");

    manager = new DefaultDesktopManager() {
      public void activateFrame(JInternalFrame f) {
        super.activateFrame(f);
      }
    };

    desktop.setDesktopManager(manager);

    //Setup the menubar
    JMenuBar menubar = new JMenuBar();
    setJMenuBar menubar;

    //Setup the menus
    JMenuFile file = new FileMenu(actions);
    menubar.add(file);

    addWindowListener(new WindowAdapter() {
      public void windowClosing (WindowEvent e) {
	System.out.println(e);
	close();
      }
    });

    getContentPane().add(toolBar, BorderLayout.NORTH);
  }

  public void addToDesktop(JInternalFrame internalFrame) {
    desktop.add(internalFrame);
    internalFrame.show();
  }

  public void quit() {
    this.dispose();
    System.exit(0);
  }
}

Undo and Redo >>