JInternalFameTest.java - Internal Frame Class Test
<< Creating Internal Frames inside the Main Frame
<< Java Swing Tutorials - Herong's Tutorial Examples
This section provides a tutorial example on how to use javax.swing.JInternalFame class to create 2 internal frames in the main frame.
The following program shows you how to create internal frames:
/** * JInternalFrameTest.java * Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/ */ import java.awt.*; import javax.swing.*; public class JInternalFrameTest { public static void main(String[] a) { JFrame myFrame = new JFrame("Internal Frames"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.setSize(300,300); JDesktopPane myDesktop = new JDesktopPane(); myFrame.setContentPane(myDesktop); JInternalFrame f = createFrame("Frame 1"); f.setLocation(10,10); myDesktop.add(f); f = createFrame("Frame 2"); f.setLocation(60,60); myDesktop.add(f); myFrame.setVisible(true); } private static JInternalFrame createFrame(String t) { JInternalFrame f = new JInternalFrame(t); f.setResizable(true); f.setClosable(true); f.setMaximizable(true); f.setIconifiable(true); f.setSize(200,200); f.setVisible(true); return f; } }
Run this program and you should see two internal frames. You can resize, close, maximize, and minimize the internal frame:
Sample programs listed in this section have been tested with JDK 1.3.1, 1.4.1, 1.5.0 and 1.6.0.
Last update: 2009.
Sections in This Chapter
javax.swing.JInternalFame - Internal Frame Class
javax.swing.InternalFrameListener - Internal Frame Listener Interface