Java Swing Tutorials - Herong's Tutorial Examples
∟Creating Internal Frames inside the Main Frame
∟JInternalFameTest.java - Internal Frame Class Test
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.
Table of Contents
About This Java Swing Tutorial Book
Introduction of Java Swing Package
Graphics Environment of the Local System
JFrame - Main Frame Class
JLabel - Swing Label Class
JButton - Swing Button Class
JRadioButton - Swing Radio Button Class
JTextField - Swing Text Field Class
Menu Bar, Menus, Menu Items and Listeners
►Creating Internal Frames inside the Main Frame
javax.swing.JInternalFame - Internal Frame Class
►JInternalFameTest.java - Internal Frame Class Test
javax.swing.InternalFrameListener - Internal Frame Listener Interface
Layout of Components in a Container
LookAndFeel and UIManager
Option Dialog Boxes
JEditorPane - The Editor Pane Class
References
Printable Copy - PDF Version