Java Swing Tutorials - Herong's Tutorial Examples - v4.32, by Herong Yang
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) 1997-2024 HerongYang.com. All Rights Reserved.
*/
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:
Table of Contents
Introduction of Java Swing Package
Graphics Environment of the Local System
JCheckBox - Swing Check Box Class
JRadioButton - Swing Radio Button Class
JTextField - Swing Text Field Class
JComboBox - Swing Combo Box 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
JEditorPane - The Editor Pane Class
SwingWorker - The Background Task Worker
AWT (Abstract Windows Toolkit)