The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JDesktop and JInternalFrame  [2 examples]

e841. Creating a JDesktopPane Container

A desktop is a container that can only hold internal frames (JInternalFrame objects). This example creates a desktop with an internal frame.
    // Create an internal frame
    boolean resizable = true;
    boolean closeable = true;
    boolean maximizable  = true;
    boolean iconifiable = true;
    String title = "Frame Title";
    JInternalFrame iframe = new JInternalFrame(title, resizable, closeable, maximizable, iconifiable);
    
    // Set an initial size
    int width = 200;
    int height = 50;
    iframe.setSize(width, height);
    
    // By default, internal frames are not visible; make it visible
    iframe.setVisible(true);
    
    // Add components to internal frame...
    iframe.getContentPane().add(new JTextArea());
    
    // Add internal frame to desktop
    JDesktopPane desktop = new JDesktopPane();
    desktop.add(iframe);
    
    // Display the desktop in a top-level frame
    JFrame frame = new JFrame();
    frame.getContentPane().add(desktop, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);

 Related Examples
e842. Getting All Frames in a JDesktopPane Container

See also: Actions    JButton    JCheckBox    JComboBox    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.